开发者

create a .war file from gwt-project

开发者_JAVA百科

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


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.


Using Eclipse:

  1. right click the project

  2. choose Google→GWT Compile

  3. when compilation has finished, the console will say i.e.

    Linking into /home/janus/bpworkspace/gwtwerkstatt2/war/gwtwerkstatt2

    Link succeeded

    Compilation succeeded -- 28.623s

  4. open a terminal and navigate to the directory

  5. create the WAR: jar cv * > /tmp/myGWTproject.war

  6. you can now launch it with jetty-runner or similar: java -jar jetty-runner-8.1.7.v20120910.jar /tmp/myGWTproject.war


I just found this solution, and it's amazing :) Just install the jar and enjoy extracting to a war file.

Project Site http://code.google.com/p/gwt-project-export-wizard/


One can also use webAppCreator to generate Ant build file.

webAppCreator ships with GWT SDK and also with Eclipse GWT Plugin. First locate GWT plugin directory

find $HOME/.eclipse/ -name "*gwt*sdk*"

this will output GWT plugin dir path. This dir has gwt dir something like gwt-2.4.0. WebAppCreator will be in this dir. Set this dir as GWTSDK_HOME.

export GWTSDK_HOME=/home/m/.eclipse/org.eclipse.platform_3.7.0_1364963873/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0

make webAppCreator executable

chmod 755 $GWTSDK_HOME/webAppCreator

Now create a project using webAppCreator in some temp dir.

$GWTSDK_HOME/webAppCreator -out fins in.m.fins.Fins

in.m.fins.Fins is the module name. This has to match with your project's gwt.xml in Eclipse workspace. If your gwt.xml is src/in/m/fins/Fins.gwt.xml then module name should be in.m.fins.Fins

-out fins will create the project and build.xml in fins directory. Copy generated build.xml file to your project in Eclipse workspace.

Run war target in Eclipse Ant Window to package your project as war


You have to have GWT designer installed from here

http://dl.google.com/eclipse/inst/d2gwt/latest/3.7

  1. In Eclipse on the main panel click on "Deploy module on aplication server" (It's next to blue google button).
  2. Chose war file name and location where to store it
  3. Click ok

That's it. Works on my GWT 2.4.0, Google Plugin for Eclipse 4.2, Eclipse Juno


For future reference: you'll find another tutorial on how to create a .war using Eclipse on http://blog.elitecoderz.net/.


Fist compile your project. Then: 1. Open your project. 2. Navigate to war folder. 3. Go to File>Export>Archive File 4. Export your war FOLDER as zip file. 5. Change your file extension form .zip to .war 6. Keep calm and enjoy your war file.


Compile your project. Then:

  1. Open your project.
  2. Navigate to war folder.
  3. Go to File>Export>Archive File
  4. Export your war FOLDER as zip file.
  5. Change your file extension form .zip to .war
  6. Keep calm and enjoy your war file.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜