How to setup GWT for Tomcat?

前端 未结 4 537
傲寒
傲寒 2021-02-14 08:43

I am new to GWT and learning it via the the Google documents. How do I setup GWT with Tomcat? I am required to intergrate it with Tomcat for work purposes.

4条回答
  •  执笔经年
    2021-02-14 09:01

    A more convenient method to run GWT in Development mode on external tomcat server is as follows. It involves two parts

    • Point tomcat to war dir of Gwt project in workspace
    • Run GWT in development mode on external server

    I will be using following paths and names in this example

    • Web App Name - Fins
    • Project location - $HOME/workspace/fins
    • Project war directory - $HOME/workspace/fins/war
    • CATALINA_HOME - $HOME/apache-tomcat-7.0.29 (tomcat installation dir)

    First step is to point tomcat to war dir of GWT project. One method to run GWT on external server is to copy static, image files and gwt dir to tomcat/webapps dir. On any changes in server side classes (like rcp etc) or static files we have to copy them again. This will be cumbersome during develpment cycle. Instead we can point tomcat to project's war directory so that tomcat runs the app directly from eclipse workspace. On any changes in project tomcat will do a reload.

    To do this, add .xml (Fins.xml in this example) to $CATALINA_HOME/conf/Catalina/localhost with following content

     
    

    This is actually context.xml file found in META-INF of tomcat application but named as .xml. In case project use any JNDI datasources, they have to be added to this file.

    • DocBase attribute points to project's war dir in eclipse. With this tomcat is able to run the web app directly from eclipse workspace without copying files to tomcat/webapps dir.
    • Reloadable attribute ensures that tomcat reloads the app whenever files are modified in eclipse.

    Now start tomcat. Check that application runs properly. Make some change in eclipse and app will be reload by tomcat. Cross verify the same in tomcat logs.

    Now to second part. We can use GWT code sever feature as detailed in GWT Debug

    To do this go to "Run As" option in project context menu and select "Web Application (Running on external server)". Enter external server root as Fins and give html page as Fins.html. This will run the GWT app in development mode without running embedded Jetty server.

    But it will still point to http://localhost:8888/Fins/Fins.html. We have to edit Run configuration to change Jetty port 8888 to tomcat's 8080.

    Go to run configurations and select Fin.html (external). Change browser field in GWT tab to http://localhost:8080/Fins/Fins.html


    enter image description here


    Run and access the app at

    http://localhost:8080/Fins/Fins.html?gwt.codesvr=127.0.0.1:9997

    Now you will be able to use GWT development mode fully.

提交回复
热议问题