【问题标题】:Issue with Maven Eclipse plugin and openjpa enhancementMaven Eclipse 插件和 openjpa 增强的问题
【发布时间】:2012-08-12 06:25:33
【问题描述】:

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

所以从编程方面来说,我们不能在 Maven 上一键构建整个项目,这有点笨拙,必须先让 STS(Eclipse)build 项目然后运行 ​​Ant 脚本到 @ 987654326@实体,然后refresh项目,然后refreshserver deployment。不是很有效。

我想这是一段时间的问题,所以创建此线程以查看是否有任何更新。

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

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

很高兴了解任何建议。谢谢。

【问题讨论】:

  • 你找到好的解决方案了吗?每次我更改实体时,它都不会在 IDE 进行的构建过程中自动增强;我必须手动调用 Maven 来执行此操作。
  • @Caffé 我没有。所以我使用 Ant 脚本来完成这项工作,这样我就可以从 UI 中调用它。看起来 Maven Eclipse 插件仍然对 OpenJPA 不满意.. :(

标签: java eclipse maven openjpa


【解决方案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 旁边(在 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>

【讨论】:

    【解决方案2】:

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

    希望对你有所帮助。

    【讨论】:

    • 感谢您的回复。实际上我也通过 Ant 运行增强,但我真的希望找到一个解决方案来让一切都通过 Maven/Pom 发生。
    猜你喜欢
    • 2012-10-11
    • 1970-01-01
    • 2021-12-30
    • 2011-11-09
    • 2019-03-30
    • 2011-03-20
    • 2011-04-10
    • 2014-06-07
    • 1970-01-01
    相关资源
    最近更新 更多