How do I create a .war-file from my gwt-project in eclipse?
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.
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.
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.jar
to 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:
right click the project
choose Google→GWT Compile
when compilation has finished, the console will say i.e.
Linking into /home/janus/bpworkspace/gwtwerkstatt2/war/gwtwerkstatt2
Link succeeded
Compilation succeeded -- 28.623s
open a terminal and navigate to the directory
create the WAR: jar cv * > /tmp/myGWTproject.war
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With