Datanucleus 编程 API 类增强
Posted
技术标签:
【中文标题】Datanucleus 编程 API 类增强【英文标题】:Datanucleus Programmatic API Class Enhancement 【发布时间】:2013-11-16 14:46:05 【问题描述】:我使用的是 Eclipse 3.7 (OSGI),我可以进行手动增强(将 Datanucleus Eclipse 插件和 datanucleus-enhancer-2.1.0-release 作为插件依赖项导入)
我现在正在尝试使用 API 类增强功能:http://www.datanucleus.org/products/accessplatform/jpa/enhancer.html#api
在类路径中使用 ASM 3.1 和此代码:
DataNucleusEnhancer enhancer=new DataNucleusEnhancer("JDO","ASM");
enhancer.setVerbose(true);
enhancer.addClasses(...);
enhancer.enhance();
我明白了:
You have selected to use ClassEnhancer "ASM" yet the JAR for that enhancer does not seem to be in the CLASSPATH!
org.datanucleus.enhancer.NucleusEnhanceException: You have selected to use ClassEnhancer "ASM" yet the JAR for that enhancer does not seem to be in the CLASSPATH!
at org.datanucleus.enhancer.DataNucleusEnhancer.init(DataNucleusEnhancer.java:224)
at org.datanucleus.enhancer.DataNucleusEnhancer.addClasses(DataNucleusEnhancer.java:406)
使用教程中建议的代码:
JDOEnhancer enhancer = JDOHelper.getEnhancer();
enhancer.setVerbose(true);
enhancer.addClasses(...);
enhancer.enhance();
我明白了:
javax.jdo.JDOFatalUserException: There are 0 services entries for the JDOEnhancer; there were no valid JDOEnhancer implementations found in the CLASSPATH. The file META-INF/services/javax.jdo.JDOEnhancer should name the implementation class.
有没有办法实现 API 类增强?
【问题讨论】:
【参考方案1】:查看此链接http://www.datanucleus.org/products/accessplatform_3_0/enhancer.html#runtime
特别是一句:“运行时增强需要以下运行时依赖项:ASM 和 DataNucleus 核心库。”
所以您可能缺少 ASM 依赖项。
尝试添加此依赖项:
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>4.2</version>
</dependency>
【讨论】:
我的依赖项中有 ASM jar。我相信这个问题与 Eclipse OSGI 层有关,它阻止了 DN 找到 ASM。以上是关于Datanucleus 编程 API 类增强的主要内容,如果未能解决你的问题,请参考以下文章
Class org.datanucleus.api.jdo.JDOPersistenceManagerFactory was not found
Class org.datanucleus.api.jdo.JDOPersistenceManagerFactory was not found
Spark SQL Hive Datanucleus jar 类路径
Datanucleus/JDO,持久化和检索 java.util.Set 属性