在Tomcat中部署GWT/GWTP应用



我知道这可能与编程没有直接关系。我希望它能在这里放得下。我有一个GWTP web应用程序,在开发模式下运行得非常好,无论是从eclipse还是从命令提示符运行mvn gwt:run。现在我尝试在本地将它部署到Tomcat 7。我运行gwt:compile并将zip文件(重命名为.war后)复制到webapps文件夹中。该应用程序列在Tomcat的管理器gui中。但是当我尝试导航到localhost:8080/appname或localhost:8080/appname/Project.html时,我只得到404错误。我错过了什么?为了完整起见,下面是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd ">4.0.0

<groupId>testproject</groupId>
<artifactId>testme-gwtp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>GWTP Basic</name>
<description>Basic GWTP application</description>
<properties>
    <!-- client -->
    <gwt.version>2.6.0</gwt.version>
    <gwtp.version>1.2.1</gwtp.version>
    <gin.version>2.1.2</gin.version>
    <!-- server -->
    <guice.version>3.0</guice.version>
    <!-- testing -->
    <junit.version>4.7</junit.version>
    <jukito.version>1.4</jukito.version>
    <!-- maven -->
    <gwt-maven-plugin.version>2.6.0</gwt-maven-plugin.version>
    <maven-surefire-plugin.version>2.6</maven-surefire-plugin.version>
    <maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version>
    <maven-resources-plugin.version>2.5</maven-resources-plugin.version>
    <maven-processor-plugin.version>2.0.5</maven-processor-plugin.version>
    <maven-build-helper-plugin.version>1.7</maven-build-helper-plugin.version>

    <target.jdk>1.7</target.jdk>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
</properties>
<build>
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
    <plugins>
        <!-- JUnit Testing - skip *.GwtTest cases -->
        <!-- 'mvn test' - runs the Jukito tests -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven-surefire-plugin.version}</version>
            <configuration>
                <includes>
                    <include>**/*Test.java</include>
                </includes>
                <excludes>
                    <exclude>**/*GwtTest.java</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <!-- GWT -->
        <!-- 'mvn gwt:run' - runs development mode -->
        <!-- 'mvn gwt:debug' - runs debug mode -->
        <!-- 'mvn gwt:compile' - compiles gwt -->
        <!-- 'mvn integration-test' - runs the gwt tests (*GwtTest.java) -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>${gwt.version}</version>
            <configuration>
                <!-- With multiple tests use GwtTestSuite.java for speed -->
                <includes>**/*GwtTest.java</includes>
                <extraJvmArgs>-Xss1024K -Xmx1024M -XX:MaxPermSize=256M</extraJvmArgs>
                <copyWebapp>true</copyWebapp>
                <hostedWebapp>${webappDirectory}</hostedWebapp>
                <runTarget>Project.html</runTarget>
                <modules>
                    <module>testproject.Project</module>
                </modules>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<dependencies>
    <!-- Google Web Toolkit -->
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>${gwt.version}</version>
    </dependency>
    <!-- GWT-Platform -->
    <dependency>
        <groupId>com.gwtplatform</groupId>
        <artifactId>gwtp-all</artifactId>
        <version>${gwtp.version}</version>
    </dependency>
    <!-- DI -->
    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>${guice.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-servlet</artifactId>
        <version>${guice.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-assistedinject</artifactId>
        <version>${guice.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.gwt.inject</groupId>
        <artifactId>gin</artifactId>
        <version>${gin.version}</version>
    </dependency>
    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jukito</groupId>
        <artifactId>jukito</artifactId>
        <version>${jukito.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- Hibernate -->
    <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.5.Final</version>
    </dependency>
    <!-- hSQLDB -->
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.3.2</version>
    </dependency>
    <!-- add slf4j interfaces to classpath -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
    <!--  GWT-Log -->
    <dependency>
        <groupId>com.allen-sauer.gwt.log</groupId>
        <artifactId>gwt-log</artifactId>
        <version>3.3.0</version>
    </dependency>                   
</dependencies>

谢谢:)

似乎您的gwt-maven-plugin 目标不绑定到任何maven 阶段。试试这样做:

<executions>
    <execution>
        <phase>compile</phase>
        <goals>
            <goal>compile</goal>
            <goal>test</goal>
        </goals>
    </execution>
</executions>

为了使它运行,您需要按照Vadim所说的做,但也必须将此添加到pom.xml:

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>gwt-maven-plugin</artifactId>
                                    <versionRange>[2.4.0,)</versionRange>
                                    <goals>
                                        <goal>resources</goal>
                                        <goal>compile</goal>
                                        <goal>i18n</goal>
                                        <goal>generateAsync</goal>
                                        <goal>test</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

如果您指定编译阶段为<phase>prepare-package</phase>,则在调用mvn package时,它将作为打包前的最后一步执行。

最新更新