本地 tomcat 中的 GWT 应用程序:nocache.js 404 未找到
GWT application in local tomcat: nocache.js 404 not found
目前我正在尝试构建 (maven) 和 运行 (tomcat 6.0.36) GWT 应用程序。该应用程序在 eclipse 中运行良好,构建成功。 tomcat 启动期间没有问题。
当我调用着陆页时,出现了 HTTP 404 错误,因为 nochache.js 文件不存在。展开的 war 目录中没有 nochache.js 文件是正确的。但为什么?任何的想法?
Firebug:
Html 文件:
<script type="text/javascript" language="javascript" src="dashboard/dashboard.nocache.js"></script>
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Dashboard</groupId>
<artifactId>Dashboard</artifactId>
<version>0.0.6-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.5.0</gwtVersion>
<gwtp.version>0.7</gwtp.version>
<agoVersion>2.7.4</agoVersion>
<oracleJdbcVersion>11</oracleJdbcVersion>
<!-- 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.smartgwt</groupId>
<artifactId>smartgwt</artifactId>
<version>4.0</version>
</dependency>
<dependency>
...
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<!-- ========================================== -->
<!-- ================== Logger ================ -->
<!-- ========================================== -->
<dependency>
<groupId>com.allen-sauer.gwt.log</groupId>
<artifactId>gwt-log</artifactId>
<version>3.1.8</version>
</dependency>
<!-- ========================================== -->
<!-- ================== GWT ================ -->
<!-- ========================================== -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.web.bindery</groupId>
<artifactId>requestfactory-server</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.web.bindery</groupId>
<artifactId>requestfactory-apt</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<!-- MVP component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-mvp-client</artifactId>
<version>${gwtp.version}</version>
<scope>compile</scope>
</dependency>
<!-- Dispatch component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-client</artifactId>
<version>${gwtp.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-server-guice</artifactId>
<version>${gwtp.version}</version>
</dependency>
<!-- Crawler component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-crawler</artifactId>
<version>${gwtp.version}</version>
</dependency>
<!-- Annotation component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-processors</artifactId>
<version>${gwtp.version}</version>
</dependency>
<dependency>
<groupId>com.google.gwt.inject</groupId>
<artifactId>gin</artifactId>
<version>1.5.0</version>
</dependency>
<!-- Some more third-party dependencies -->
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>com.googlecode.gflot</groupId>
<artifactId>gflot</artifactId>
<version>3.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>oracle</groupId>
<artifactId>oracle</artifactId>
<version>11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gwtext</groupId>
<artifactId>gwtext</artifactId>
<version>2.0.5</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtVersion}</version>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin
documentation at codehaus.org -->
<configuration>
<runTarget>Dashboard.html</runTarget>
<module>com.xxx.dashboards.Dashboard</module>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<pluginExecutions>
<pluginExecution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>generateAsync</goal>
</goals>
</pluginExecution>
</pluginExecutions>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.10.v20130312</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<repositories>
...
</repositories>
</project>
我的 pom.xml 需要做任何调整吗?
您为 gwt-maven-plugin 配置执行的方式是错误的:它应该是 <executions>
和 <execution>
而不是 <pluginExecutions>
和 <pluginExecution>
, 他们应该在 <configuration>
.
之外
并且您必须从 <build>
/<plugins>
引用 gwt-maven-plugin,而不仅仅是 <pluginManagement>
(它适用于 maven-compiler-plugin,因为它隐式绑定到编译阶段<packaging>war</packaging>
; jetty-maven-plugin 没问题,因为它会从命令行调用)
附带说明:将所有 GWT 依赖项(gwt-servlet 除外,尤其是 gwt-user)与 <scope>provided</scope>
放在一起,以避免将它们捆绑到 WAR 中。另外,requestfactory-apt 是编译期用的,运行时没用,所以也用 <scope>provided</scope>
; requestfactory-server 是 gwt-servlet 的一个子集,因此您不需要两者。
不过,我强烈建议您将项目分成几个模块,一个模块用于 GWT 客户端代码,一个模块用于服务器端代码(可能还有第三个模块用于您在客户端和服务器之间共享的代码,例如GWT-RPC 或 RequestFactory 接口,以及您将通过 GWT-RPC 传输的 类。
它适用于以下生命周期映射。
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId> org.apache.maven.plugins </groupId>
<artifactId> maven-dependency-plugin
</artifactId>
<versionRange> [2.1,) </versionRange>
<goals>
<goal>unpack</goal>
<goal>build-classpath</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId> gwt-maven-plugin </artifactId>
<versionRange> [2.5.0,) </versionRange>
<goals>
<goal>generateAsync</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.bsc.maven</groupId>
<artifactId> maven-processor-plugin </artifactId>
<versionRange> [2.0.5,)
</versionRange>
<goals>
<goal>process</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId> org.codehaus.mojo </groupId>
<artifactId>
build-helper-maven-plugin
</artifactId>
<versionRange> [1.7,) </versionRange>
<goals>
<goal>add-source</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archiver</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
目前我正在尝试构建 (maven) 和 运行 (tomcat 6.0.36) GWT 应用程序。该应用程序在 eclipse 中运行良好,构建成功。 tomcat 启动期间没有问题。
当我调用着陆页时,出现了 HTTP 404 错误,因为 nochache.js 文件不存在。展开的 war 目录中没有 nochache.js 文件是正确的。但为什么?任何的想法?
Firebug:
Html 文件:
<script type="text/javascript" language="javascript" src="dashboard/dashboard.nocache.js"></script>
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Dashboard</groupId>
<artifactId>Dashboard</artifactId>
<version>0.0.6-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.5.0</gwtVersion>
<gwtp.version>0.7</gwtp.version>
<agoVersion>2.7.4</agoVersion>
<oracleJdbcVersion>11</oracleJdbcVersion>
<!-- 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.smartgwt</groupId>
<artifactId>smartgwt</artifactId>
<version>4.0</version>
</dependency>
<dependency>
...
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<!-- ========================================== -->
<!-- ================== Logger ================ -->
<!-- ========================================== -->
<dependency>
<groupId>com.allen-sauer.gwt.log</groupId>
<artifactId>gwt-log</artifactId>
<version>3.1.8</version>
</dependency>
<!-- ========================================== -->
<!-- ================== GWT ================ -->
<!-- ========================================== -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.web.bindery</groupId>
<artifactId>requestfactory-server</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.web.bindery</groupId>
<artifactId>requestfactory-apt</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<!-- MVP component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-mvp-client</artifactId>
<version>${gwtp.version}</version>
<scope>compile</scope>
</dependency>
<!-- Dispatch component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-client</artifactId>
<version>${gwtp.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-server-guice</artifactId>
<version>${gwtp.version}</version>
</dependency>
<!-- Crawler component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-crawler</artifactId>
<version>${gwtp.version}</version>
</dependency>
<!-- Annotation component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-processors</artifactId>
<version>${gwtp.version}</version>
</dependency>
<dependency>
<groupId>com.google.gwt.inject</groupId>
<artifactId>gin</artifactId>
<version>1.5.0</version>
</dependency>
<!-- Some more third-party dependencies -->
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>com.googlecode.gflot</groupId>
<artifactId>gflot</artifactId>
<version>3.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>oracle</groupId>
<artifactId>oracle</artifactId>
<version>11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gwtext</groupId>
<artifactId>gwtext</artifactId>
<version>2.0.5</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtVersion}</version>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin
documentation at codehaus.org -->
<configuration>
<runTarget>Dashboard.html</runTarget>
<module>com.xxx.dashboards.Dashboard</module>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<pluginExecutions>
<pluginExecution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>generateAsync</goal>
</goals>
</pluginExecution>
</pluginExecutions>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.10.v20130312</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<repositories>
...
</repositories>
</project>
我的 pom.xml 需要做任何调整吗?
您为 gwt-maven-plugin 配置执行的方式是错误的:它应该是 <executions>
和 <execution>
而不是 <pluginExecutions>
和 <pluginExecution>
, 他们应该在 <configuration>
.
之外
并且您必须从 <build>
/<plugins>
引用 gwt-maven-plugin,而不仅仅是 <pluginManagement>
(它适用于 maven-compiler-plugin,因为它隐式绑定到编译阶段<packaging>war</packaging>
; jetty-maven-plugin 没问题,因为它会从命令行调用)
附带说明:将所有 GWT 依赖项(gwt-servlet 除外,尤其是 gwt-user)与 <scope>provided</scope>
放在一起,以避免将它们捆绑到 WAR 中。另外,requestfactory-apt 是编译期用的,运行时没用,所以也用 <scope>provided</scope>
; requestfactory-server 是 gwt-servlet 的一个子集,因此您不需要两者。
不过,我强烈建议您将项目分成几个模块,一个模块用于 GWT 客户端代码,一个模块用于服务器端代码(可能还有第三个模块用于您在客户端和服务器之间共享的代码,例如GWT-RPC 或 RequestFactory 接口,以及您将通过 GWT-RPC 传输的 类。
它适用于以下生命周期映射。
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId> org.apache.maven.plugins </groupId>
<artifactId> maven-dependency-plugin
</artifactId>
<versionRange> [2.1,) </versionRange>
<goals>
<goal>unpack</goal>
<goal>build-classpath</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId> gwt-maven-plugin </artifactId>
<versionRange> [2.5.0,) </versionRange>
<goals>
<goal>generateAsync</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.bsc.maven</groupId>
<artifactId> maven-processor-plugin </artifactId>
<versionRange> [2.0.5,)
</versionRange>
<goals>
<goal>process</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId> org.codehaus.mojo </groupId>
<artifactId>
build-helper-maven-plugin
</artifactId>
<versionRange> [1.7,) </versionRange>
<goals>
<goal>add-source</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archiver</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>