2013-04-16 58 views
3

我有一個項目,我想使用eclipse GWT工具(開發模式和調試器)與GWT/Appengine/Maven應用程序進行交互I正在寫作。我的事情有點正常,但我仍然有一些事情沒有完成。如果有人能夠幫助我解決這些問題,我會發布POM文件。GWT + Appengine + JPA + Eclipse + Maven:如何讓它們一起工作

  • 當我做了Maven->更新項目,我失去在eclipse項目屬性的AppEngine性質和必須去屬性,谷歌的AppEngine並重新檢查使用谷歌應用程序引擎。在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:插件(Bundle)」org.datanucleus「已經被註冊了,確保你在類路徑中沒有多個JAR版本的同一個插件,URL」file :/ 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,我與公司和項目名稱一起使用了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> 

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

On編輯:下面是第3點的解決方案。禁用項目屬性 - Google - App Engine頁面中的JPA/JDO。轉到構建路徑並刪除所有作爲頂級庫列出的datanucleus庫(通過在項目屬性中啓用appengine來放置這些庫)。確保Maven依賴關係位於Order選項卡的列表底部。

On編輯2:我找到了一種方法來保持GAE項目的性質,當我做Maven-> Update Project時。我已將此添加到POM(即使我使用Eclipse構建安裝M2E)

  <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解決(種)。我仍然需要一種方法來解決第二點,儘管如果我記得這樣做,解決方法很簡單。我記得這樣做後,我更擔心那些獲得代碼的人。

我也在尋找一種方式,以不使用Eclipse啓動的。我知道這可以通過添加各種配置文件和配置來完成。我只需要找到正確的配置來做到這一點。通過這個,我的意思是一個配置文件,它將以開發模式(或超級開發模式)運行gwt代碼,以及一個將以開發模式運行帶有gwt代碼的調試器的配置文件。


上編輯3:我解決了子彈點2.這是因爲關閉項目 - >自動構建簡單。我不確定首先發生了什麼。

這就是所有解決的3個要點。在這一點上,我可能應該爲這個問題創建一個答案,並將它標記爲對那些對此感興趣並且沒有讀到的人。我會在一兩天內做到這一點(當我有時間撰寫一個很好的答案時)。

+0

你有沒有通過GWT樣品POM文件@ https://code.google.com/p/google-web-toolkit/source/browse/trunk/samples/mobilewebapp/pom.xml和https不見了。 google.com/p/google-web-toolkit/source/browse/trunk/samples/dynatablerf/pom.xml和https://code.google.com/p/google-web-toolkit/source/browse/trunk/樣品/驗證/ pom.xml – SSR

+0

我已經看過那些。第一個使用Objectify(而不是JPA)並使用不同的appengine插件:net.kindleit maven-gae-plugin。第二個和第三個沒有任何幫助,因爲他們似乎沒有使用應用程序引擎。謝謝。 – Deanna

回答

1

它看起來像你的maven設置是好的,但讓我做一些可能有所幫助的觀察。

1)我們只是執行同樣的事情Maven的DataNucleus將-插件我會刪除從AppEngine上,Maven的插件enhancerApi。因此,不要運行appengine:增強目標以及datanucleus插件的目標。

2)DataNucleus將插件的設置既提升域類,這聽起來我的權利,但只是驗證這一點,我猜。

3)我不再是最好的日食了,但我很好奇你使用的maven插件,m2eclipse插件是由sonatype開發的,在我看來是最準確的插件。

4)編譯戰爭插件的執行似乎是我錯了,因爲這應該默認爲package階段,無論如何,確保其他階段已正確執行事前。

5)您可能需要獲得設立幾個執行指令的插件,或者依賴於默認,如果它們存在。 maven的生命週期可能有點棘手,我建議您閱讀http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html,並確保eclipse在啓動應用程序之前運行正確的階段。 //代碼:

+0

謝謝。我從appengine-maven插件中刪除了enhancerApi。你的第二點是正確的。我只想增強域類。我正在使用eclipse J2ee Juno附帶的m2eclipse - 這是sonatype插件。我將刪除戰爭插件 - 這是我在玩清單文件時發生的。我會再次閱讀生命週期階段,但maven構建部分似乎正在工作。這只是越來越與它整合,我遇到了問題。再次感謝。 – Deanna

+0

我想你可能需要定義war插件,因爲你可以像這樣對archiveClasses說:https://github.com/mattstep/appengine-guestbook-java/blob/master/pom.xml#L82。我的直覺是,m2eclipse插件正在對階段和生命週期進行一些假設,當你得到這個結果時,eclipse很可能會開始更加順暢地運行Maven。 – MattStep

+0

謝謝。我從未深入研究過m2eclipse生命週期管理。我看到有一個可以覆蓋的xml文件。這將需要一些研究。我會給它一個鏡頭。 – Deanna