GWT模块......在项目源或资源中找不到

时间:2013-03-10 13:20:35

标签: java gwt

我是GWT的新手。我尝试制作一个Web应用程序并使用以下maven配置来配置gwt。我把它放在一个配置文件中,所以只有在调用配置文件时才会编译gwt。

个人资料如下:

<profiles>
        <profile>
            <id>gwtCompile</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>gwt-maven-plugin</artifactId>
                        <version>2.5.0</version>
                        <configuration>
                            <extraJvmArgs>-Xmx512M -Xss1024k </extraJvmArgs>
                            <module>com.mycompany.MyMainModule</module>
                            <inplace>true</inplace>
                            <force>true</force>
                            <disableCastChecking>true</disableCastChecking>
                            <style>PRETTY</style>
                            <warSourceDirectory>${basedir}/war</warSourceDirectory>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>com.google.gwt</groupId>
                                <artifactId>gwt-user</artifactId>
                                <version>${gwt.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>com.google.gwt</groupId>
                                <artifactId>gwt-dev</artifactId>
                                <version>${gwt.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>compileJS</id>
                                <phase>process-classes</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

当我运行命令时:

   mvn clean install -Dmaven.test.skip=true -PgwtCompile

它给了我错误信息:

GWT Module com.mycompany.MyMainModule not found in project sources or resources.

我的MyMainModule.gwt.xml是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<module>
    <inherits name='com.google.gwt.user.User' />

    <entry-point class='com.mycompany.MyMainModule' />

    <source path='client' />
    <source path='shared' />
</module>

我可以看到一些在线文档说多个模块项目应该有这个错误。但是mime不是一个多模块项目。

有人能告诉我这可能出了什么问题吗?

非常感谢。

编辑:

我已经实现了这个目标:

<resources>
    <resource>
        <directory>${basedir}/src/main/java</directory>
        <includes>
            <include>**/client/**</include>
            <include>**/*.gwt.xml</include>
        </includes>
    </resource>
    <resource>
        <directory>${basedir}/src/main/resources</directory>
        <includes>
            <include>**/*</include>
        </includes>
    </resource>
</resources>

3 个答案:

答案 0 :(得分:4)

尝试在构建代码中添加资源标记。

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/java</directory>
        </resource>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
        </resource>
    </resources>
    <!-- **Other build tags** -->
</build>

答案 1 :(得分:3)

我找到了解决方法。问题是gwt-maven-plugin中指定的模块必须是.gwt.xml文件的确切路径名,而不是入口点文件。

所以配置文件必须是:

<configuration>
    <extraJvmArgs>-Xmx512M -Xss1024k </extraJvmArgs>
    <module>com.mycompany.myoroject.MyMainModule</module>
    <inplace>true</inplace>
    <force>true</force>
    <disableCastChecking>true</disableCastChecking>
    <style>PRETTY</style>
    <warSourceDirectory>${basedir}/war</warSourceDirectory>
</configuration>

因为我的MyMainModule.gwt.xml位于src / main / com / mycompany / myproject / MyMainModule.gwt.xml下。

非常感谢你的回答。

答案 2 :(得分:1)

重要的配置变量是outputDirectory和webappDirectory。见这里:

<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
            ">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.gwt</groupId>
    <artifactId>gwt-ui-sandbox</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>GWT UI Sandbox</name>

    <properties>
        <license.licenseName>apache_v2</license.licenseName>
        <license.inceptionYear>2012</license.inceptionYear>

        <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
        <default.encoding>UTF-8</default.encoding>
        <project.build.sourceEncoding>${default.encoding}</project.build.sourceEncoding>
        <project.reporting.outputEncoding>${default.encoding}</project.reporting.outputEncoding>
        <maven.compiler.plugin.encoding>${default.encoding}</maven.compiler.plugin.encoding>
        <gwt.version>2.5.0</gwt.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </dependency>        
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
    </dependencies>


    <build>
        <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>**/*.css</exclude>
                    <exclude>**/Messages.properties</exclude>
                </excludes>
            </resource>
        </resources>        

        <plugins>
            <!--            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <id>first</id>
                        <goals>
                            <goal>update-file-header</goal>
                        </goals>
                        <phase>process-sources</phase>
                    </execution>
                </executions>
            </plugin>-->

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
            </plugin>

            <!-- Copy static web files before executing gwt:run -->
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <webappDirectory>${webappDirectory}</webappDirectory>
                </configuration>                
            </plugin>

            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1.2</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>            

            <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.8.1</version>
            </plugin>

            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.9.v20130131</version>
                <executions>                
                    <execution>
                        <id>start-jetty</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>deploy-war</goal>
                        </goals>
                        <configuration>
                            <daemon>true</daemon>
                            <scanIntervalSeconds>0</scanIntervalSeconds>

                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-jetty</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>    
                <configuration>
                    <systemProperties>
                        <systemProperty>
                            <name>some.prop</name>
                            <value>false</value>
                        </systemProperty>
                    </systemProperties>
                    <stopKey>stop</stopKey>
                    <stopPort>8079</stopPort>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>${gwt.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>css</goal>
                            <goal>i18n</goal>
                            <goal>generateAsync</goal>
                            <!-- package source files with .class files: -->
                            <!-- (this is not good for dev mode incremental parsing) -->
                            <!-- <goal>resources</goal> -->
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <runTarget>index.html</runTarget>
                    <hostedWebapp>${webappDirectory}</hostedWebapp>
                    <compileReport>false</compileReport>
                    <style>PRETTY</style>
                    <draftCompile>true</draftCompile>
                    <logLevel>INFO</logLevel>

                    <mode>manual</mode>
                    <productionMode>true</productionMode>
                    <remoteweb>rmi://127.0.0.1/chromium</remoteweb>
                    <browser>/usr/bin/chromium-browser</browser>
                    <timeOut>${gwt.timeout}</timeOut>

                    <i18nMessagesBundles>
                        <!-- need to compile only one language in order to make the compiler happy... -->
                        <!-- My guess: GWT seems to directly use the properties files when using translations from sub-modules -->
                        <i18nMessagesBundle>com.gwt.uisandbox.Messages</i18nMessagesBundle>
                    </i18nMessagesBundles>

                    <cssFiles>
                        <cssFile>com/gwt/uisandbox/Style.css</cssFile>
                    </cssFiles>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>process-resources</phase>
                        <configuration>
                            <target>
                                <!-- http://code.google.com/p/google-web-toolkit/issues/detail?id=4599 -->
                                <replace dir="${basedir}">
                                    <include name="target/generated-sources/gwt/com/gwt/uisandbox/Style.java"/>
                                    <replacetoken>interface Style extends CssResource {</replacetoken>
                                    <replacevalue>public interface Style extends CssResource {</replacevalue>
                                </replace>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>                        
                    </execution>
                </executions>
            </plugin>

            <!-- http://maven.apache.org/plugins/maven-enforcer-plugin/plugin-info.html -->
            <plugin>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>enforce-sane-versions</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requirePluginVersions />
                                <DependencyConvergence />
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.5</version>
                </plugin>        
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.6</version>
                </plugin>        
                <plugin>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.1.2</version>
                </plugin>        
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.7</version>
                </plugin>        
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.4</version>
                </plugin>        
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.2</version>
                </plugin>        
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                </plugin>        
                <plugin>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>1.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.9</version>
                </plugin>                
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.13</version>
                </plugin>        
            </plugins>
        </pluginManagement>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.7</version>
            </dependency>
            <dependency>
                <groupId>com.google.gwt</groupId>
                <artifactId>gwt-user</artifactId>
                <version>${gwt.version}</version>
                <!-- netbeans needs provided scope to find gwt sources (when debuggung) -->
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.6.6</version>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.4</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

(见here

BTW:在构建一个包含在另一个最终编译的UI模块中的模块时,你应该只将java文件放入最终结果(就像其他响应所示)。否则,它会破坏gwt:run。

的增量java解析机制