怎么办OpenJPA的增强与ANT + IntelliJ IDEA的 [英] How to do OpenJPA enhancement with Ant + IntelliJ IDEA

查看:612
本文介绍了怎么办OpenJPA的增强与ANT + IntelliJ IDEA的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是快把我逼疯了,我很震惊,官方文档是绝对useles。

下面是我:


  • IntelliJ IDEA的11

  • OpenJPA的2.1.1

由于OpenJPA的加入到使用的库列表中我已经有classpath中到OpenJPA它看起来像这样

 <路径ID =library.openjpa.classpath>
    <文件集DIR =$ {} BASEDIR / lib目录/ OpenJPA的>
        < patternset REFID =library.patterns/>
    < /文件集>
< /路径>

根据官方文档,我添加以下目标

 <目标名称=提升>
    <复制includeemptydirs =假todir =$ {} BASEDIR / lib目录/ OpenJPA的>
        <文件集DIR =SRC排除=** / *的推出,** / * java的。/>
    < /复制>    <的taskdef NAME =openjpac类名=org.apache.openjpa.ant.PCEnhancerTask>
        <类路径REFID =library.openjpa.classpath/>
    < /&的taskdef GT;    < openjpac>
        <类路径REFID =library.openjpa.classpath/>
    < / openjpac>
< /目标与GT;

这让我异常


  

C:\\工作\\ PRJ \\的build.xml:283:org.apache.openjpa.util.MetaDataException:
  MetaDataFactory无法配置
  (conf.newMetaDataFactoryInstance()返回NULL)。这可能意味着
  没有配置属性被发现了。请确保你有一个
  META-INF / persistence.xml文件,它是在你的类路径,
  或属性文件正在使用的配置
  可用。如果您在使用Ant,请参阅或
   属性任务的嵌套元素。
  这也可能发生,如果你的OpenJPA的分布罐子损坏,或
  如果你的安全策略是过于严格的。


进程监视器测试,可以看到,它的打开和读取 的persistence.xml

有些人归档的bug 有我有问题,他得到的回答是,找到的persistence.xml 不是问题的根源。

问题是:


  1. 我能做些什么使它工作?

  2. 我能让它跳过需要的persistence.xml ,只对指定的.class文件我想加强?
  3. 工作模式
  4. 它更蚂蚁的问题。我怎样才能让OpenJPA增强寻找的persistence.xml 比在其他目录 OpenJPA的-2.1.1.jar 驻留?


解决方案

所以,我不能使它没有无证工作 propertiesFile 。下面是对我的作品的版本。还可以通过使得它失败的NullReferenceException指定持久性单元。

 <目标名称=提升>
    <的taskdef NAME =openjpac类名=org.apache.openjpa.ant.PCEnhancerTask>
        <类路径REFID =library.openjpa.classpath/>
    < /&的taskdef GT;    < openjpac>
        <类路径REFID =library.openjpa.classpath/>
        <类路径位置=$ {} reporting.output.dir/>
        <配置propertiesFile =$ {} BASEDIR /src/META-INF/persistence.xml/>
    < / openjpac>
< /目标与GT;

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 ?

解决方案

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>

这篇关于怎么办OpenJPA的增强与ANT + IntelliJ IDEA的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆