2012-08-15 46 views
2

我們當前的項目是將Spring 3/OpenJPA與Roo和Maven集成到STS(Eclipse)中。 M2E插件有點問題,因爲它無法處理實體增強。Maven Eclipse插件和openjpa增強的問題

因此,從程序方面,它是一個有點笨拙,我們不能一個鍵建立在Eclipse的下Maven的整個項目,但必須讓STS(Eclipse)build項目,然後再運行Ant腳本enhance實體,然後refresh該項目,然後refreshserver deployment。不是很有效。

我想這是一段時間的問題,所以創建此線程以查看是否有任何更新。

似乎有一個工具可用(OpenJPA Eclipse Tooling Builder)但似乎不支持最新的Eclipse(STS 2.9.1基於Eclipse 3.7,該工具只覆蓋3.4)。

所以問題變成:有什麼辦法可以將所有東西(build,compile with enhancement)整合在一起(可能只在Maven中設計POM)?

樂於學習任何建議。謝謝。

+0

您是否找到一個好的解決方案?每次我更改一個實體時,它都不會在IDE進行的構建過程中自動增強;我必須手動調用Maven來執行此操作。 – 2014-09-23 17:41:41

+0

@Caffé我沒有。所以我使用Ant腳本來完成這個工作,所以我可以從UI中調用它。它看起來Maven Eclipse插件仍然不滿意OpenJPA .. :( – Dreamer 2014-09-23 18:16:04

回答

0

@Subarule我沒有使用Maven,但只有ANT用於我的項目,以下ANT腳本有助於增強我的構建。

<target name="enhance" depends="compile"> 
    <echo message="Enhancing...."/> 
    <!-- ***************************************************************************************************************** --> 
    <!-- DO NOT DELETE FOLLOWING CODE. THIS IS ADDED FOR ENCHANCING THE CLASSES AT COMPILE TIME. IT IS REQUIRED BY OPENJPA --> 
    <!-- Define the classpath to include the necessary files. --> 
    <!-- ex. openjpa jars, persistence.xml, orm.xml, and target classes --> 
    <path id="jpa.enhancement.classpath"> 
     <!-- Assuming persistence.xml/orm.xml are in META-INF --> 
     <pathelement location="META-INF" /> 

     <!-- Location of the .class files --> 
     <pathelement location="${build.classes}" /> 

     <!-- Add the openjpa jars --> 
     <fileset dir="OpenJPA_lib_jar"> 
       <include name="*.jar" /> 
     </fileset> 
    </path> 
    <!-- This is a bit of a hack, but I needed to copy the persistence.xml file from my src dir 
     to the build dir when we run enhancement --> 
    <!--<copy includeemptydirs="false" todir="bin"> 
     <fileset dir="src" excludes="**/*.launch, **/*.java"/> 
    </copy>--> 

    <!-- define the openjpac task; this can be done at the top of the --> 
    <!-- build.xml file, so it will be available for all targets --> 
    <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask" classpathref="jpa.enhancement.classpath" /> 

    <!-- invoke enhancer on all .class files below the model directory --> 
    <openjpac> 
     <classpath refid="jpa.enhancement.classpath" /> 
     <fileset dir="."> 
      <include name="**/model/*.class" /> 
     </fileset> 
     <config propertiesFile = "${basedir}/src/META-INF/persistence.xml"/> 
    </openjpac> 
    <echo message="Enhancement complete" /> 
    <!-- ***************************************************************************************************************** --> 
</target> 

希望這可以幫助你。

+0

謝謝你的迴應。其實我通過Ant運行增強,但我真的希望找到一個解決方案,使所有事情都由Maven/Pom發生。 – Dreamer 2012-08-16 20:52:31

1

我在eclipse kepler和OpenJPA 2.2.1中遇到了同樣的問題。

該解決方案非常簡單,但有點骯髒。

首先,您需要從該網站上安裝OpenJPA的M2E連接器:

http://openjpa-maven-connector.googlecode.com/svn/trunk/openjpa-connector-update-site

接下來,您必須修改POM,並把旁邊的OpenJPA的,Maven的插件的ELEMENTO插件(build元素內),下一個定義:

<pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId>openjpa-maven-plugin</groupId> 
            <artifactId>openjpa-maven-plugin</artifactId> 
            <versionRange>[1.0,)</versionRange> 
            <goals> 
             <goal>enhance</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <execute /> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

所以構建元素應該看起來像這樣(用自己的實體包):

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</version> 
      <configuration> 
       <verbose>true</verbose> 
       <compilerVersion>1.6</compilerVersion> 
       <source>1.6</source> 
       <target>1.6</target> 
       <debug>true</debug> 
       <debuglevel>lines,vars,source</debuglevel> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.openjpa</groupId> 
      <artifactId>openjpa-maven-plugin</artifactId> 
      <version>2.2.1</version> 
      <executions> 
       <execution> 
        <id>mappingtool</id> 
        <phase>process-classes</phase> 
        <goals> 
         <goal>enhance</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <includes> 
        com/xxxx/xxxx/* 
       </includes> 
      </configuration> 
     </plugin> 
    </plugins> 

    <pluginManagement> 
     <plugins> 
      <!--This plugin definition only affects eclipse, not the mvn command execution --> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId>openjpa-maven-plugin</groupId> 
            <artifactId>openjpa-maven-plugin</artifactId> 
            <versionRange>[1.0,)</versionRange> 
            <goals> 
             <goal>enhance</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <execute /> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build>