gpt4 book ai didi

google-app-engine - GWT + Appengine + JPA + Eclipse + Maven:如何使它们协同工作

转载 作者:太空宇宙 更新时间:2023-11-03 15:36:51 26 4
gpt4 key购买 nike

我有一个项目,我想使用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类,然后才能使用“运行方式-Web应用程序”启动器运行它们。 Maven构建具有适用于构建中的域对象的测试用例-我在构建“ maven-datanucleus-plugin:3.1.3:enhance(默认)”中看到为此目的而增强的类。但是,作为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“已注册,并且您试图注册位于相同的插件网址为“文件:/ 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。“”。我尝试了各种操作,例如删除数据核插件和/或依赖项,各种配置选项,以及在应用引擎属性面板中取消选中“使用Datnucleus JDO / JPA访问数据存储区”。有没有办法让它工作?


下面是我与公司和项目名称x'ed一起使用的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。转到构建路径,并删除所有列为顶级库的数据核库(通过在项目属性中启用appengine将它们放置在此处)。确保Maven依赖项位于“顺序”选项卡上列表的底部。

在Edit 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启动器的方法。我知道可以通过添加各种配置文件和配置来完成。我只需要找到正确的配置即可。我的意思是,一个配置文件将在dev模式(或超级开发模式)下运行gwt代码,并且一个配置文件将在dev模式下使用gwt代码运行调试器。



在Edit 3上,我解决了要点2。这就像自动关闭Project-> Build一样简单。我不确定首先要做什么。

这是所有3个要点已解决。在这一点上,我可能应该为这个问题创建一个答案,并将其标记为对那些对此感兴趣并且还没有读完为止的人解决了。我将在一两天内(当我有时间撰写一个不错的答案时)进行此操作。

最佳答案

看来您的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在启动应用程序之前运行正确的阶段。

关于google-app-engine - GWT + Appengine + JPA + Eclipse + Maven:如何使它们协同工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16039522/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com