Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create a .war file from gwt-project

Tags:

java

tomcat

war

gwt

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

like image 294
derp Avatar asked Mar 23 '11 09:03

derp


People also ask

How do you create WAR file?

You can create the war itself by running mvn package or deploy it by setting up a server in eclipse and simply adding adding the project to the server.

What is GWT create?

GWT. create is used by the GWT compiler for deferred binding. Deferred binding is a feature of the GWT compiler that works by generating many versions of code at compile time, only one of which needs to be loaded by a particular client during bootstrapping at runtime.


4 Answers

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.

like image 155
Chris Boesing Avatar answered Sep 21 '22 02:09

Chris Boesing


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

like image 33
Janus Troelsen Avatar answered Sep 22 '22 02:09

Janus Troelsen


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/

like image 31
MattWeiler Avatar answered Sep 23 '22 02:09

MattWeiler


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

like image 37
Maithilish Avatar answered Sep 21 '22 02:09

Maithilish