There are only two simple steps to take, to build a .war from your GWT project:
Short version:
The first step is building a .jar from your src-folder and putting the .jar into the lib-folder of the .war-folder of your GWT-project. The second step is building a .war-file from your war-folder and deploying the .war to your tomcat server. To make the second step more compfortable, I wrote a little Ant-script, that will create the .war.
More detailed – Step 1:
| 1) Right-click the src folder inside your project. | |
| 2) The following PopUp-menu will appear.
Select “Export …” from this menu. |
|
| 3) Select “JAR file” from the next window | |
| 4) Make sure, only the “src”-folder of your project is checked in the next window.
Select the export destination like this: <folder of your project>/war/WEB-INF/lib/<projectname>.jar – then click “Finish” |
Now your GWT-project is ready to be packed into a .war, that can be deployed to a tomcat server.
More detailed – Step 2:
1) Create a new ANT-script in your project (Right-click your project folder and select “New” and then select “File” from the submenu. Call the new file “warbuilder.xml” or something like this.).
2) Copy the following content into the newly created file. Replace <projectname> with the name of your project:
<project name="<projectname>" basedir="." default="default"> <target name="default" depends="buildwar,deploy"></target> <target name="buildwar"> <war basedir="war" destfile=" <projectname>.war" webxml="war/WEB-INF/web.xml"> <exclude name="WEB-INF/**" /> <webinf dir="war/WEB-INF/"> <include name="**/*.jar" /> </webinf> </war> </target> <target name="deploy"> <copy file=" <projectname>.war" todir="." /> </target> </project>
3) The first two steps must be done only once. You can reuse the warbuilder.xml and do not have to build it every time. Now simply right-click the “warbuilder.xml” and select “Run As” and “Ant Build” from the PopUp-menu.
The .war-File will be created by this ANT-script. You will find the .war-file in your ProjectFolder.
10.12.2009 19:19:19 com.google.apphosting.utils.jetty.JettyLogger warn
WARNUNG: Nested in javax.servlet.ServletException: init:
java.lang.NoClassDefFoundError: org/jibble/pircbot/PircBot
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
This exception can occure, when you try to use an .jar with GWT on the server side. The error message tells you, that the included path to your .jar (in this case org.jibble.pircbot.PircBot) can not be found. This normally happens, when you have forgotten to put the .jar into your build-path. When running GWT, the normal include into the build-path is not everything you need to do:
The normal way to include the .jar to your build-path is to edit the properties of your project, by right-clicking your project. In the
appearing window, you select “Java Build Path”. There you normally add your external .jars.
When using the GWT-Plugin in eclipse, this isn’t the only thing you have to do. Additionally, you need to copy the .jar into the WAR-directory of your project. The exact path is: YouProject/war/WEB-INF/lib/.
After putting the .jar into this directory, your local GWT-Runtime will work and not throw this error again. The reason is, that the GWT-Runtime of eclipse does not use the eclipse environment. It uses only the files of your “war”, which will be deployed to your application-server later.