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!

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

  • singha sagt:

    Thanks for your posting. This article ‘s very helpful to me.

  • Rafael sagt:
  • Nate sagt:

    Thanks, it appears to be just what I’m looking for to test my new (and first) Tomcat installation. I’ll try it Monday.

    It appears that your script/application puts Time() at Time() in the message headers rather than Date() at Time().

    Therefor I have no idea if this is a thread is still live…

  • Tarek sagt:

    Thank you ! it work fine

  • shoxx sagt:

    Good article Everything work fine but I have some problem.. when I open myPage.html it work fine but if I call my project by this url “localhost:8080/myProject/myPage.html”
    I found error 404 can someone solve my problem

    thanks for help. Nuttee From Thailand

  • shoxx sagt:

    plz forget my problem.. i solution it by mapping servlet in web.xml

  • phot0 sagt:

    Hi man,
    It looks really nice, but it’s not working here.
    I do everything as said and when I run on tomcat it doesn’t work.
    At chrome debugger it says:
    Failed to load resource: the server responded with a status of 404 (Not Found) :P roject.css
    Failed to load resource: the server responded with a status of 404 (Not Found) :8080/Project/project/servlet?

    and the same for my other servlets

    Any Idea of how to make it work??
    Thankss!

  • Frank sagt:

    Thank you!

  • joe sagt:

    It doesn’t seem like creating the .jar from the src folder is necessary. I’m not sure why it’s being done for deployment purposes? None of that code is compiled into either javascript or java. It seems like something that you would do if you were packaging everything into a jar file so that another module could inherit it and that other module would be able to run a debugger and see the source code.

  • AngiSad sagt:

    Hi,
    I followed your tutorial but I got the message “GWT module needs to be (re) compiled” once i try to access the app.
    Can you tell me what I missed plz?
    Thanx.

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Get in contact:

Kategorien