How to do OpenJPA enhancement with Ant + IntelliJ IDEA

試著忘記壹切 提交于 2019-12-07 03:54:25

问题


This is driving me crazy and I'm shocked that official documentation is absolutely useles.

Here is what I have:

  • IntelliJ IDEA 11
  • OpenJPA 2.1.1

Since openjpa is added into list of used libraries I already had classpath to OpenJPA which looks like this

<path id="library.openjpa.classpath">
    <fileset dir="${basedir}/lib/openjpa">
        <patternset refid="library.patterns"/>
    </fileset>
</path>

According to official documentation I added following target

<target name="enhance">
    <copy includeemptydirs="false" todir="${basedir}/lib/openjpa">
        <fileset dir="src" excludes="**/*.launch, **/*.java"/>
    </copy>

    <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
        <classpath refid="library.openjpa.classpath"/>
    </taskdef>

    <openjpac>
        <classpath refid="library.openjpa.classpath"/>
    </openjpac>
</target>

It gives me exception

C:\work\prj\build.xml:283: org.apache.openjpa.util.MetaDataException: MetaDataFactory could not be configured (conf.newMetaDataFactoryInstance() returned null). This might mean that no configuration properties were found. Ensure that you have a META-INF/persistence.xml file, that it is available in your classpath, or that the properties file you are using for configuration is available. If you are using Ant, please see the or attributes of the task's nested element. This can also occur if your OpenJPA distribution jars are corrupt, or if your security policy is overly strict.

I tested with Process Monitor and can see that it opens and reads persistence.xml.

Some person filed bug having problems I have and the answer he got was that finding persistence.xml is not a source of problem.

Questions are:

  1. What can I do to make it work ?
  2. Can I make it work by skipping need for persistence.xml and just specifying pattern for .class files I want to be enhanced ?
  3. It's more Ant question. How can I make OpenJPA enhancer to look for persistence.xml in directory other than where openjpa-2.1.1.jar resides ?

回答1:


So I couldn't make it work without undocumented propertiesFile. Here is version that works for me. Also specifying persistence-unit via # makes it fail with NullReferenceException.

<target name="enhance">
    <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
        <classpath refid="library.openjpa.classpath"/>
    </taskdef>

    <openjpac>
        <classpath refid="library.openjpa.classpath"/>
        <classpath location="${reporting.output.dir}"/>
        <config propertiesFile = "${basedir}/src/META-INF/persistence.xml"/>
    </openjpac>
</target>



回答2:


It appears that you might have missed an important part from the documentation. Your library.openjpa.classpath is missing a reference to your Entities, and the location of the persistence.xml file. Try adding that and see how it goes.

<path id="jpa.enhancement.classpath">
  <pathelement location="bin"/> <!-- add something like this -->

  <!-- lib contains all of the jars that came with the OpenJPA binary download -->
  <fileset dir="lib">
    <include name="**/*.jar"/>
  </fileset>
</path>


来源:https://stackoverflow.com/questions/8574004/how-to-do-openjpa-enhancement-with-ant-intellij-idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!