Home > GWT > GWT und tomcat: .war erzeugen mit eclispe um .war auf tomcat zu deployen

GWT und tomcat: .war erzeugen mit eclispe um .war auf tomcat zu deployen

Wie man mit eclipse kompfortabel ein .war aus einem GWT-Projekt erzeugt, um es auf einem tomcat-Server zu deployen.

Im Grunde genommen sind es nur zwei einfache Schritte, um aus dem GWT-Projekt ein .war zu erzeugen:

Kurzversion:

Als erstes wird ein .jar aus dem “src”-Verzeichnis des Projektes generiert, welches in das “lib”-Verzeichnis des “war”-Verzeichnisses des GWT-Projektes gelegt werden muß. Der zweite Schritt ist dann das eigentliche generieren der .war-Datei, welche dann auf den tomcat-server deployed werden kann. Um den zweiten Schritt etwas kompfortabler zu gestalten habe ich hierfür ein Ant-Script geschrieben, welches das eigentliche .war erzeugt.

Detailierte Version – Schritt 1:

right_click_src

1) Rechts-Klick auf das "src"-Verzeichnis (anklicken für größere Darstellung)

1) Rechts-Klick auf das src Verzeichnis innerhalb des Projektes.

popup_export

2) "Export" anklicken (anklicken für größere Darstellung)

2) Das nebenstehende PopUp erscheint.

Aus diesem Menü “Export …” wählen.

Select_export_format

3) Exportformat: "JAR File" (anklicken für größere Darstellung)

3) Nun “JAR file” als Export-Format wählen

select_export_source_and_target

3) Quelle und Ziel auswählen (anklicken für größere Darstellung)

4) Es darf nur das “src”-Verzeichnis des Projektes ausgewählt sein.

Als Ziel für den Export muß folgender Pfad angegeben werden: <Verzeichnis des Projektes>/war/WEB-INF/lib/<projectname>.jar – dann auf “Finish” klicken.

Nun ist das GWT-Projekt soweit vorbereitet, daß es in ein .war gepackt werden kann um auf einem tomcat-Server deployed zu werden.

Detailierte Version – Schritt 2:

1) Es wird ein neues ANT-Script innerhalb des Projektes erstellt (Rechts-Klick auf das Projektverzeichnis, dann “New” und vom Untermenü “File” auswählen. Die neue Datei sollte z.B. “warbuilder.xml” heissen).

2) Folgender Inhalt muß in diese Datei kopiert werden. Dabei <projectname> durch den Namen des Projektes ersetzen:

<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>

run_ant_script

5) Run the warbuilder ANT-script (click for larger view)

3) Die ersten beiden Schritte müssen für jedes Projekt nur einmal ausgeführt werden. Danach kann der warbuilder.xml immer wieder benutzt werden. Um das .war nun zu erzeugen klickt man einfach mit der rechten Maustaste auf den warbuilder.xml und wählt vom PopUp-Menü den Punkt “Run as” und vom Submenü “Ant Build” aus.

Die .war-Datei wird dann durch das ANT-Script erzeugt. You will find the .war-file in your ProjectFolder.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Tweet This Post

KategorienGWT Tags: , , , , ,
  1. 14:32, 14:32 | #1

    thanks !! works well

  2. Mikel
    15:51, 15:51 | #2

    Hey,

    absolutely perfect; this is what i would like to call “missing manual” for GWT-Deployment!

    Thank you so much!

    Mikel from Germany

  3. Nikhil Dhavale
    09:52, 09:52 | #3

    I mean how to deploy it on tomcat . Any command line commands for the same

  4. 10:45, 10:45 | #4

    @Nikhil Dhavale: After running the ant-script, you have to deploy the generated .war to your tomcat, using the default-upload service of your tomcat-manager. If you have no access to the tomcat-manager, you can also directly copy the file into the “webapps”-folder of your tomcat.

  5. Robert
    09:34, 09:34 | #5

    Thanks a lot, it’s working fine.

  6. andy christianson
    20:01, 20:01 | #6

    I can confirm this works as well. Thanks!

  7. Tiago Megas
    15:31, 15:31 | #7

    You are the man o/

    Thanks for the help!

  8. ja
    00:45, 00:45 | #8

    thank you very much !

  9. Koyote
    19:05, 19:05 | #9

    Man!! you save me a bunch of time to resolve this f… problem.
    Greetings from Mexico.

  10. saggy
    13:10, 13:10 | #10

    thanks dear, you saved my plenty of hours…thanks a lot from india

  11. efe
    02:33, 02:33 | #11

    thanks a lot! I wish google was this clear on this :)

  12. Mehul
    12:39, 12:39 | #12

    its shows that gwt modules recompile when i deploye that war file on to the tomcat 5.5

  13. 13:11, 13:11 | #13

    @Mehul
    What do you mean by that?

  14. Firefly
    14:14, 14:14 | #14

    It is important to note, that prior to performing any of these steps, you need to (in Eclipse):
    - perform a clean on the project making sure the “Start a build automatically ” checkbox is NOT checked;
    - right click on the project and select Google, followed by GWT Compile
    - Then build the jar and war file as described above.
    Otherwise, after you deploy the war to Apache Tomcat the error “gwt module may need to be (re)compiled” will appear, when you click on the application to bring it up in a browser.

    Btw, excellent instructions on how to build the jar and war file. Thanks a lot!

  15. David
    13:32, 13:32 | #15

    Thanks a lot!!! It was very useful for me.

  16. muhskel
    17:56, 17:56 | #16

    thanks a lot, Google should implement this feature for eclipse.

  17. Srini
    06:49, 06:49 | #17

    perfect. Thank you for the tip

  1. Bisher keine Trackbacks