3

我有一个项目,我想使用 eclipse GWT 工具(开发模式和调试器)与我正在编写的 GWT/Appengine/Maven 应用程序进行交互。我有一些工作秩序,但仍有一些事情在我不正确的边缘。如果有人可以帮助我解决这几个问题,我将发布 POM 文件。

  • 当我执行 Maven->Update Project 时,我在 eclipse 项目属性中失去了 appengine 的性质,必须转到 Properties、Google、AppEngine 并重新检查 Use Google App Engine。我可以在 POM 中做些什么而不失去 appengine 的性质吗?我正在使用 Google appengine-maven-plugin 插件。这似乎是官方使用的。
  • 在构建 maven 之后,我必须先清理项目以增强 jpa 类,然后才能使用 Run As - Web Application 启动器运行它们。maven 构建具有在构建中工作的域对象的测试用例 - 我看到在构建 'maven-datanucleus-plugin:3.1.3:enhance (default)' 中针对此目标增强的类。但是作为一个 Web 应用程序运行它会抛出错误,告诉我类没有得到增强,除非我做了一个项目清理,这会导致 eclipse 做它的增强。有没有办法避免这个额外的步骤?
  • 我无法运行 JUnit View 测试运行程序或使用使用该视图的启动器。JUnit 视图抱怨:“引起:org.datanucleus.exceptions.NucleusException:插件(捆绑)“org.datanucleus”已注册。确保类路径中没有同一插件的多个 JAR 版本。URL“文件:/C:/Users/bondsd/.m2/repository/org/datanucleus/datanucleus-core/3.1.3/datanucleus-core-3.1.3.jar" 已经注册,并且您正在尝试注册一个相同的插件位于在 URL “file:/C:/Program%20Files/eclipse/plugins/com.google.appengine.eclipse.sdkbundle_1.7.5/appengine-java-sdk-1.7.5/lib/opt/user/datanucleus/v2/datanucleus -core-3.1.3.jar.""。我尝试了各种方法,例如删除 datanucleus 插件和/或依赖项,各种配置选项,并取消选中应用引擎属性面板中的“使用 Datnucleus JDO/JPA 访问数据存储区”。有没有办法让它工作?

下面是我使用的 POM,其中公司和项目名称已删掉。如果您需要启动器,我也很乐意发布它们。在此先感谢您提供任何建议或帮助。我已经搜索了互联网,但还没有找到合适的解决方案。

<modelVersion>4.0.0</modelVersion>

<groupId>com.xxx.xxxx</groupId>
<artifactId>shell</artifactId>
<packaging>war</packaging>
<version>0.1.0-proto</version>

<name>XXXXXX</name>
<description>A XXXXXXXX</description>

<properties>
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- GWT version -->
    <gwt.version>2.5.1</gwt.version>
    <gwt.style>PRETTY</gwt.style>

    <!-- GAE version -->
    <appengine.version>1.7.6</appengine.version>
    <appengine.sdk.version>1.7.6</appengine.sdk.version>
    <appengine.orm.version>2.1.2</appengine.orm.version>
    <appengine.port>8888</appengine.port>
    <datanucleus.core.version>3.1.3</datanucleus.core.version>
    <datanucleus.api.version>3.1.3</datanucleus.api.version>
    <datanucleus.enhancer.version>3.1.1</datanucleus.enhancer.version>
    <datanucleus.plugin.version>3.1.3</datanucleus.plugin.version>

    <slf4jVersion>1.6.6</slf4jVersion>
    <log4j.version>1.3</log4j.version>
    <junit.version>4.11</junit.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.google.gwt.inject</groupId>
        <artifactId>gin</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-servlet</artifactId>
        <version>3.0</version>
    </dependency>

    <!-- GWT dependencies -->
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-servlet</artifactId>
        <version>${gwt.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>${gwt.version}</version>
        <scope>provided</scope>
    </dependency>



    <!-- GAE SDK -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>${appengine.version}</version>
    </dependency>

    <!-- For the servlet filter -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <!-- <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> 
        <version>1.2</version> </dependency> -->


    <!-- RequestFactory server -->
    <dependency>
        <groupId>com.trycatchsoft.gwt.requestfactory</groupId>
        <artifactId>injected-requestfactory</artifactId>
        <version>1.2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.google.web.bindery</groupId>
        <artifactId>requestfactory-server</artifactId>
        <version>${gwt.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.web.bindery</groupId>
        <artifactId>requestfactory-apt</artifactId>
        <version>${gwt.version}</version>
    </dependency>


    <!-- RequestFactory will use JSR 303 javax.validation -->

    <!-- Validation API -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>

    <!-- Validation Implementation -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.3.0.Final</version>
    </dependency>


    <!--Test Dependencies -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.0</version>
        <scope>test</scope>
    </dependency>
    <!-- GAE libraries for local testing as described here: http://code.google.com/appengine/docs/java/howto/unittesting.html -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-labs</artifactId>
        <version>${appengine.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-stubs</artifactId>
        <version>${appengine.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-testing</artifactId>
        <version>${appengine.version}</version>
        <scope>test</scope>
    </dependency>

    <!-- End of Test Dependencies -->

    <!-- JPA 2.0 for GAE -->
    <dependency>
        <groupId>com.google.appengine.orm</groupId>
        <artifactId>datanucleus-appengine</artifactId>
        <version>${appengine.orm.version}</version>
    </dependency>
    <!-- Datanucleus -->
    <!-- datanucleus-core is not needed for compilation. in fact, it cannot 
        have compile scope because the datanucleus plugin automatically adds it during 
        enhancement and complains if there are two copies. app should not depend 
        on any classes in this lib anyways. -->
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-core</artifactId>
        <version>${datanucleus.core.version}</version>
        <scope>runtime</scope>
        <exclusions>
            <exclusion>
                <groupId>javax.transaction</groupId>
                <artifactId>transaction-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- datanucleus-jpa is needed during compilation for its @Extension annotation 
        which is used throughout entity classes -->
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-api-jpa</artifactId>
        <version>${datanucleus.api.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jpa_2.0_spec</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.0.0</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.7.2</version>
    </dependency>
    <!-- SLF4J logging libraries -->
    <!-- <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> 
        <version>${slf4jVersion}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> 
        <artifactId>slf4j-log4j12</artifactId> <version>1.7.2</version> </dependency> 
        <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> 
        </dependency> -->

    <!-- End SLF4J logging libraries -->
</dependencies>




<build>
    <!-- Generate compiled stuff in the folder used for developing mode -->
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>

    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
            <dependencies>
                <!-- Need to run the RF Validation tool. This works on both the command-line 
                    and in Eclipse, provided that m2e-apt is installed. -->
                <dependency>
                    <groupId>com.google.web.bindery</groupId>
                    <artifactId>requestfactory-apt</artifactId>
                    <version>${gwt.version}</version>
                </dependency>
            </dependencies>
        </plugin>


        <!-- GWT Maven Plugin -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.5.1-rc1</version>
            <dependencies>
                <!-- Force plugin to use same gwt version -->
                <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>
            <configuration>
                <strict>true</strict>
                <extraJvmArgs>-Xss1024K -Xmx1024M -XX:MaxPermSize=256M</extraJvmArgs>
                <logLevel>INFO</logLevel>
                <style>${gwt.style}</style>
                <copyWebapp>true</copyWebapp>
                <hostedWebapp>${webappDirectory}</hostedWebapp>
                <runTarget>Shell.html</runTarget>
                <webappDirectory>${webappDirectory}</webappDirectory>
                <module>com.ihg.dashboard.Shell</module>
                <server>com.google.appengine.tools.development.gwt.AppEngineLauncher</server>
                <i18nMessagesBundle>com.ihg.dashboard.client.Messages</i18nMessagesBundle>
                <appEngineVersion>${appengine.version}</appEngineVersion>
                <!-- Should GWT create the Story of Your Compile Report -->
                <compileReport>false</compileReport>
            </configuration>                
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test</goal>
                        <goal>i18n</goal>
                    </goals>
                </execution>
            </executions>

        </plugin>

        <plugin>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>${appengine.version}</version>
            <configuration>
                <jvmFlags>
                    <jvmFlag>-Ddatastore.backing_store=${project.basedir}\local_db.bin</jvmFlag>
                </jvmFlags>
                <enhancerApi>JPA</enhancerApi>
            </configuration>
        </plugin>


        <!-- This plug-in "enhances" your domain model objects (i.e. makes them 
            persistent for datanucleus) -->
            <!--  Might not need this, appengine is supposed to do this appengine:enhance -->
        <plugin>
            <groupId>org.datanucleus</groupId>
            <artifactId>maven-datanucleus-plugin</artifactId>
            <version>${datanucleus.plugin.version}</version>
            <configuration>
                <mappingIncludes>**/domain/*.class</mappingIncludes>
                <metadataIncludes>**/domain/*.class</metadataIncludes>
                <verbose>false</verbose>
                <enhancerName>ASM</enhancerName>
                <api>JPA</api>
            </configuration>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <!-- enhancement requires the gwt-user jar because many of the entity 
                        classes implement IsSerializable and the enhancer needs it on the classpath 
                        to function. because the gwt-user library has a scope of provided, it is 
                        only available on the compilation and test classpath, and is not transitive 
                        to the enhancement classpath. -->
                    <groupId>com.google.gwt</groupId>
                    <artifactId>gwt-user</artifactId>
                    <version>${gwt.version}</version>
                </dependency>
                <dependency>
                    <!-- force maven-datanucleus-plugin to use the same version of datanucleus-core -->
                    <groupId>org.datanucleus</groupId>
                    <artifactId>datanucleus-core</artifactId>
                    <version>${datanucleus.core.version}</version>
                </dependency>
            </dependencies>
        </plugin>




        <!-- Copy static web files before executing gwt:run -->
        <!--  May not need this now -->
        <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>
                <webXml>${webappDirectory}/WEB-INF/web.xml</webXml>
                <webappDirectory>${webappDirectory}</webappDirectory>
            </configuration>
        </plugin>

    </plugins>



    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings 
                only. It has no influence on the Maven build itself. -->
            <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.5.1-rc1,)
                                    </versionRange>
                                    <goals>
                                        <goal>i18n</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.datanucleus
                                    </groupId>
                                    <artifactId>
                                        maven-datanucleus-plugin
                                    </artifactId>
                                    <versionRange>
                                        ${datanucleusVersion}
                                    </versionRange>
                                    <goals>
                                        <goal>enhance</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

========================================

编辑时:这是要点 3 的解决方案。在项目属性 - Google - App Engine 页面中禁用 JPA/JDO。转到构建路径并删除所有列为顶级库的 datanucleus 库(这些库是通过在项目属性中启用 appengine 来放置的)。确保 Maven 依赖项位于 Order 选项卡上列表的底部。

在编辑 2 上: 当我执行 Maven->Update Project 时,我找到了一种保持 GAE 项目性质的方法。我将此添加到 POM 中(即使我使用的是安装了 m2e 的 eclipse 构建)

            <plugin>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>false</downloadJavadocs>
                <wtpversion>2.0</wtpversion>
                <additionalBuildcommands>
                    <buildCommand>
                        <name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
                    </buildCommand>
                </additionalBuildcommands>
                <additionalProjectnatures>
                    <projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
                    <projectnature>com.google.appengine.eclipse.core.gaeNature</projectnature>
                </additionalProjectnatures>
            </configuration>
        </plugin>

这解决了要点 1。所以现在我已经解决了第 1 点和第 3 点(有点)。我仍然需要一种方法来解决要点 2,尽管如果我记得这样做的话,解决方法很容易。我更担心那些在我记得做之后得到代码的人。

我也在寻找一种根本不使用 Eclipse 启动器的方法。我知道可以通过添加各种配置文件和配置来完成。我只需要找到正确的配置来做到这一点。我的意思是一个配置文件将在开发模式(或超级开发模式)下运行 gwt 代码,以及一个配置文件将在开发模式下运行带有 gwt 代码的调试器。


在编辑 3 上:我解决了要点 2。就像关闭 Project->Build Automatically 一样简单。我不确定那是什么。

这就是解决了所有 3 个要点。在这一点上,我可能应该为这个问题创建一个答案,并将它标记为那些对此感兴趣并且没有读到这里的人。我会在一两天内完成(当我有时间撰写一个很好的答案时)。

4

1 回答 1

1

看起来你的 maven 设置很好,但让我做一些可能有帮助的观察。

1)我会从appengine-maven-plugin中删除enhancerApi,因为我们只是在执行与maven-datanucleus-plugin相同的事情。因此,不要将 appengine:enhance 目标与 datanucleus 插件的目标一起运行。

2) datanucleus 插件的设置只是为了增强域类,这对我来说听起来不错,但我猜只是验证一下。

3)我不再是 eclipse 最好的了,但我很好奇你使用的是哪个 maven 插件,m2eclipse 插件是由 sonatype 开发的,在我看来是最准确的插件。

4) 在我看来,war 插件在编译时的执行似乎是错误的,因为无论如何这都应该默认为 package 阶段,这可以确保其他阶段事先已正确执行。

5) 您可能需要为插件设置更多执行指令,或者依赖默认值(如果存在)。maven 生命周期可能有点棘手,我建议阅读http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html并确保 eclipse 在启动之前运行正确的阶段你的申请。

于 2013-04-16T18:10:57.193 回答