Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

java - create a .war file from gwt-project

How do I create a .war-file from my gwt-project in eclipse?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I always use Ant build file, so the project gets compiled and packaged as a war with one click.

Add an xml-file to your project with the following content:

<project name="test" basedir="." default="default">
<property name="src.dir" value="src" />
<property name="build.dir" value="war" />
<path id="compile.classpath">
    <fileset dir="${build.dir}/WEB-INF/lib">
        <include name="**/*.jar" />
        <include name="**/*.xml" />
    </fileset>
</path>

<target name="default" depends="gwtc, buildwar,deploy">
</target>

<target name="gwtc" description="GWT compile to JavaScript">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
        <classpath>
            <pathelement location="${src.dir}" />
            <path refid="compile.classpath" />
        </classpath>
        <arg line="-logLevel INFO" />
        <jvmarg value="-Xmx1024M" />
        <arg value="YourProject.EntryPointClass" />
    </java>
</target>

<target name="buildwar">
    <war basedir="war" destfile="YourProject.war" webxml="war/WEB-INF/web.xml">
        <exclude name="WEB-INF/**" />
        <webinf dir="war/WEB-INF/">
            <include name="**/gwt-servlet.jar" />
            <include name="**/classes/**" />
        </webinf>
    </war>
</target>

<target name="deploy">
    <copy file="YourProject.war" todir="." />
</target>

</project>

(Edit `YourProject.EntryPointClass to the path to your EntryPoint-class)

You would need to add gwt-user.jar and gwt-dev.jarto your projects build path(right click on your project -> Build Path -> Add External Achives).

If you now look at your "Problems"-view you get a warning that the two files are not available on the server's class path. You can use the QuickFix to either copy it to WEB-INF/lib or hide the warning. The build file will not include those two file in the war-file.

All you need to do to compile and create the file is to right click the xml-file and select run as Ant Build.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...