Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do OpenJPA enhancement with Ant + IntelliJ IDEA

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 ?
like image 640
expert Avatar asked Dec 20 '11 10:12

expert


1 Answers

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>
like image 193
expert Avatar answered Oct 15 '22 01:10

expert