Maven Eclipse插件和openjpa增强问题

时间:2012-08-15 22:13:52

标签: java eclipse maven openjpa

我们目前的项目是将Spring 3 / OpenJPA与Roo和maven集成在STS(Eclipse)上。 M2E插件有点问题,因为它无法处理实体增强。

所以从编程方面看,我们无法在Eclipse下通过一次点击在Maven上构建整个项目,但是必须先让STS(Eclipse)build项目,然后运行{{} 1}}脚本到Ant实体,然后enhance项目,然后refresh refresh。不太有效。

我想这是一个问题,所以创建这个线程,看看是否有任何更新。

似乎有一个可用的工具(OpenJPA Eclipse Tooling Builder)但它似乎不支持最新的Eclipse(STS 2.9.1基于Eclipse 3.7,该工具仅覆盖到3.4)。

所以问题就变成了:有什么方法(或工具)我们可以将所有东西(server deploymentbuild)整合在一起(可能只在Maven上设计POM)?

很高兴学到任何建议。谢谢。

2 个答案:

答案 0 :(得分:1)

我遇到了与eclipse kepler和OpenJPA 2.2.1相同的问题。

解决方案很简单,但有点脏。

首先,您需要从此站点安装OpenJPA m2e连接器:

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

接下来,您必须修改您的POM,并将其放在openjpa-maven-plugin插件的elemento旁边(内部构建元素),下一个定义:

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

答案 1 :(得分: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>

希望这会对你有所帮助。

相关问题