我正在使用带有 maven 插件的 gwt。我的web.xml
样子是这样的:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<!-- Servlets -->
<servlet>
<servlet-name>queryServiceImpl</servlet-name>
<servlet-class>com.vo.search.server.QueryServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>queryServiceImpl</servlet-name>
<url-pattern>/admin/queryService</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Admin.html</welcome-file>
</welcome-file-list>
</web-app>
我的模块Admin.gwt.xml
看起来像这样:
<module rename-to='admin'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name="com.google.gwt.core.Core" />
<inherits name='com.google.gwt.user.User' />
<inherits name="com.google.gwt.i18n.I18N" />
<inherits name="com.google.gwt.i18n.CldrLocales" />
<inherits name="com.google.gwt.user.theme.clean.CleanResources" />
<!-- Enable debug ID. -->
<inherits name="com.google.gwt.user.Debug" />
<set-property name="gwt.enableDebugId" value="true" />
<!-- We need the JUnit module in the main module, -->
<!-- otherwise eclipse complains (Google plugin bug?) -->
<!-- <inherits name='com.google.gwt.junit.JUnit' /> -->
<!-- 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.clean.Clean' />
<!-- <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.vo.search.client.Admin' />
<!-- Specify the app entry point class. -->
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
</module>
最后,我的pom.xml
样子是这样的:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.vo.search</groupId>
<artifactId>search-admin</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>Admin</name>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.5.0-rc1</gwtVersion>
<!-- GWT needs at least java 1.5 -->
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<classifier>sources</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.0-rc1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin
documentation at codehaus.org -->
<configuration>
<runTarget>Admin.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>com.vo.search.client.Messages</i18nMessagesBundle>
</configuration>
</plugin>
<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory} </webappDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
构建和运行项目工作正常。尝试访问我在控制台中看到的页面时:
[WARN] Aliased resource: file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/admin/admin.nocache.js==file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/Admin/Admin.nocache.js
[WARN] Aliased resource: file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/admin/admin.nocache.js==file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/Admin/Admin.nocache.js
[WARN] 404 - GET /admin/admin.nocache.js (127.0.0.1) 1408 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.39 Safari/537.4
Accept: */*
Referer: http://127.0.0.1:8888/Admin.html?gwt.codesvr=127.0.0.1:9997
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response headers
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1408
我认为问题在于它admin.nocache.js
在admin
dir 中查找文件,但生成的 dir 实际上是Admin
即使我的rename-to
属性admin
在模块配置文件中。更改rename-to
属性以匹配没有帮助。
这是我由gwt-maven-plugin archetype创建的项目组织: