GXT之旅:第一章:初识ExtGWT(3)——用tomcat运行
在tomcat上跑起来jetty是google自带的一个服务器,不用安装,Eclipse插件安装好后,就可以运行。我不知道她是否有容器可以支撑spring,hibernate等,也不知道随着项目不断壮大能否负载的了。经过反复测试,小妹我自己总结出来如何让GWT的项目既可以在jetty上跑,也可以在tomcat上跑。(但是当运行在tomcat时,client端的代码没办法跟断点debug)
·
在tomcat上跑起来
jetty是google自带的一个服务器,不用安装,Eclipse插件安装好后,就可以运行。我不知道她是否有容器可以支撑spring,hibernate等,也不知道随着项目不断壮大能否负载的了。
经过反复测试,小妹我自己总结出来如何让GWT的项目既可以在jetty上跑,也可以在tomcat上跑。(但是当运行在tomcat时,client端的代码没办法跟断点debug)
- 新建一个Dynamic Web Project
- 项目创建完毕后,右键项目,点击properties。给项目引入GWT,如截图
- 此时的项目还不是一个GWT项目,因为还没有相关的GWT配置文件,要配置GWT的Entry Point Modules(类似于flex的程序入口文件指定)项目才可以运行,我们可以把先前生成项目里面的package和java code都拷贝过来先。如下截图
- 注意0:编辑FirstApp项目的web.xml文件,删除FirstApp1项目。然后把FirstApp项目中凡是“FirstApp1”字样的“1”都给去掉。下面是几个主要文件修改后的结果
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='firstapp'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='com.danielvaughan.firstapp.client.FirstApp'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
web.xml文件修改后的内容如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>FirstApp</display-name>
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.danielvaughan.firstapp.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/firstapp/greet</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>FirstApp.html</welcome-file>
</welcome-file-list>
</web-app>
- 注意1:Java build Path里面的tomcat类库一定要在最下面,否则项目无法运行。我分析是tomcat的类库的jar包和引入的GWT:gwt-servlet.jar冲突。所以从项目在加载jar的顺序上做处理,让项目先加载gwt-servlet.jar,然后再加载tomcat相关的jar包,这样就可以避免冲突。
- 注意2:用jetty运行时,她会自动帮你编译。用tomcat运行时,则需要你手动的编译GWT。编译成功后,会在WebContent目录下生成firstapp目录,里面存放一些编译后的js等文件
- 注意3:启动tomcat前要配置勾选“Public module contexts to separate XML files”,否则项目发布不成功。
- 注意4:tomcat成功启动程序后,断点debug只能跟踪server包下的类,而client包下是没办法跟踪断点的。没办法只能同时启动jetty。我测试的url是(http://127.0.0.1:8080/FirstApp/FirstApp.html?gwt.codesvr=127.0.0.1:9997)这样任何目录下都可以跟踪断点了:)。运行效果如下
更多推荐
已为社区贡献3条内容
所有评论(0)