【问题标题】:DataNucleus enchancer cannot instantiate org.datanucleus.api.jdo.JDOAdapterDataNucleus 增强器无法实例化 org.datanucleus.api.jdo.JDOAdapter
【发布时间】:2015-07-21 10:51:45
【问题描述】:

我的代码符合要求,但是当我尝试运行 DataNucleus 增强器时,我无法完成编译后步骤。我想我缺少一个 jar 文件,但是哪个?我已经包含了错误和 pom.xml

我从谷歌页面复制说明:

<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>3.2.0-m1</version>
<configuration>
<api>JDO</api>
<props>${basedir}/datanucleus.properties</props>
<verbose>true</verbose>
<enhancerName>ASM</enhancerName>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>3.1.3</version>
</dependency>
</dependencies>
</plugin>

我得到了这个错误。

我得到这个错误。 [错误] - - - - - - - - - - [错误] 来自 DataNucleus 工具 + org.datanucleus.enhancer.DataNucleusEnhancer 的标准错误: [错误] - - - - - - - - - - [错误] 线程“main”中的异常错误:尝试实例化 API 适配器“org.datanucleus.api.jdo.JDOAdapter”的实例时发生错误(可能您在 CLASSPATH 中没有必需的 datanucleus-api-XXX jar , 或者 您正在使用的持久性规范的 jar?):{1} org.datanucleus.exceptions.NucleusUserException: Error : 尝试实例化 A 的实例时发生错误 适配器“org.datanucleus.api.jdo.JDOAdapter”(也许您在 CLAS 中没有必要的 datanucleus-api-XXX jar TH,还是您正在使用的持久性规范的 api jar?):{1} 在 org.datanucleus.api.ApiAdapterFactory.getApiAdapter(ApiAdapterFactory.java:104) 在 org.datanucleus.AbstractNucleusContext.(AbstractNucleusContext.java:115) 在 org.datanucleus.enhancer.EnhancementNucleusContextImpl.(EnhancementNucleusContextImpl.java:48) 在 org.datanucleus.enhancer.EnhancementNucleusContextImpl.(EnhancementNucleusContextImpl.java:37) 在 org.datanucleus.enhancer.DataNucleusEnhancer.(DataNucleusEnhancer.java:161) 在 org.datanucleus.enhancer.CommandLineHelper.createDataNucleusEnhancer(CommandLineHelper.java:148) 在 org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1108)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<packaging>war</packaging>
	<version>1.0-SNAPSHOT</version>

	<groupId>com.thechrisoneil.mygroupstogo</groupId>
	<artifactId>mygroupstogo</artifactId>

	<properties>
		<appengine.app.version>1</appengine.app.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<prerequisites>
		<maven>3.1.0</maven>
	</prerequisites>

	<dependencies>
		<!-- Compile/runtime dependencies, as defined by Google default maven project -->
		<!-- https://cloud.google.com/appengine/docs/java/tools/maven -->
		<dependency>
			<groupId>com.google.appengine</groupId>
			<artifactId>appengine-api-1.0-sdk</artifactId>
			<version>1.9.18</version>
		</dependency>
		<dependency>
			<groupId>com.google.appengine</groupId>
			<artifactId>appengine-endpoints</artifactId>
			<version>1.9.18</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.inject</groupId>
			<artifactId>javax.inject</artifactId>
			<version>1</version>
		</dependency>
		<dependency>
			<groupId>javax.jdo</groupId>
			<artifactId>jdo-api</artifactId>
			<version>3.1.3</version>
		</dependency>
		<!-- Dependencies added for datastorage persistents -->
		<!-- Datanucleaus (http://www.datanucleus.org/products/datanucleus/jdo/maven.html) -->
		<dependency>
			<groupId>com.google.appengine.orm</groupId>
			<artifactId>datanucleus-appengine</artifactId>
			<version>2.1.2</version>
		</dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>3.1.3</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jdo</artifactId>
            <version>3.1.3</version>
        </dependency>      
       

		<!-- Test Dependencies -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.mockito</groupId>
			<artifactId>mockito-all</artifactId>
			<version>1.9.5</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.google.appengine</groupId>
			<artifactId>appengine-testing</artifactId>
			<version>1.9.18</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.google.appengine</groupId>
			<artifactId>appengine-api-stubs</artifactId>
			<version>1.9.18</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>javax.jdo</groupId>
			<artifactId>jdo-api</artifactId>
			<version>3.0.1</version>
		</dependency>
	</dependencies>

	<build>
		<!-- for hot reload of the web application -->
		<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>versions-maven-plugin</artifactId>
				<version>2.1</version>
				<executions>
					<execution>
						<phase>compile</phase>
						<goals>
							<goal>display-dependency-updates</goal>
							<goal>display-plugin-updates</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<version>3.1</version>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.4</version>
				<configuration>
					<webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>
					<webResources>
						<resource>
							<!-- this is relative to the pom.xml directory -->
							<directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
							<!-- the list has a default value of ** -->
							<includes>
								<include>WEB-INF/*.discovery</include>
								<include>WEB-INF/*.api</include>
							</includes>
						</resource>
						<!--Development of groupstogo front end is imported to deployment server -->
						<resource>
							<directory>C:/software/angularjs/my-gtg/app</directory>
							<filtering>true</filtering>
							<includes>
								<include>**/*.js</include>
								<include>**/*.html</include>
								<include>**/*.png</include>
								<include>**/*.css</include>
							</includes>
							<targetPath>app</targetPath>
						</resource>
						
					</webResources>
				</configuration>
			</plugin>
			<plugin>
				<groupId>com.google.appengine</groupId>
				<artifactId>appengine-maven-plugin</artifactId>
				<version>1.9.18</version>
				<configuration>
					<enableJarClasses>false</enableJarClasses>
					<!-- Comment in the below snippet to bind to all IPs instead of just 
						localhost -->
					<!-- address>0.0.0.0</address> <port>8080</port -->
					<!-- Comment in the below snippet to enable local debugging with a remove 
						debugger like those included with Eclipse or IntelliJ -->
					<!-- jvmFlags> <jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag> 
						</jvmFlags -->
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>endpoints_get_discovery_doc</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>maven-datanucleus-plugin</artifactId>
                <version>3.2.0-m1</version>
                <configuration>
                    <api>JDO</api>
                    <props>${basedir}/datanucleus.properties</props>
                    <verbose>true</verbose>
                    <enhancerName>ASM</enhancerName>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.datanucleus</groupId>
                        <artifactId>datanucleus-api-jdo</artifactId>
                        <version>3.1.3</version>
                    </dependency>
                </dependencies>
            </plugin>
		</plugins>
	</build>

</project>

【问题讨论】:

  • 为什么要使用 v4.x 的 datanucleus-core/datanucleus-json 和 v3.1.x 的 datanucleus-api-jdo 和 v3.2.x 的 datanucleus Maven 插件??!完全不一致。
  • 哦,没有“javax.jdo”jdo-api v3.1.3这样的东西。
  • 您对正确版本有何建议?以下是 GAE 在他们的 [link] 上推荐的内容(cloud.google.com/appengine/docs/java/datastore/jdo/… 网站:&lt;groupId&gt;org.datanucleus&lt;/groupId&gt; &lt;artifactId&gt;datanucleus-api-jdo&lt;/artifactId&gt; &lt;version&gt;3.1.3&lt;/version&gt;
  • GAE 不提供任何引用 datanucleus 4.x 版本的内容。甚至没有 3.2.x。 Google“datanucleus-appengine”代码使用的最后一个版本是 DataNucleus v3.1.x。正如所有 appengine 文档所说,使用 jdo-api v3.0
  • 正确。那是绝望地尝试包含一个提供缺少的api的罐子。错误发生在此之前

标签: google-app-engine jdo datanucleus


【解决方案1】:

我的项目构建正常,能够生成元类并运行字节码增强器。但它是 SBT,而不是 Maven。

有兴趣的可以看看 http://github.com/frgomes/poc-scala-datanucleus

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,通过比较 https://cloud.google.com/appengine/docs/java/datastore/jdo/overview-dn2http://www.datanucleus.org/products/accessplatform_3_2/jdo/maven.html 能够解决它

    Google 的 pom.xml sn-p 中可能有一个简单的拼写错误。正如您在 DataNucleus 页面上看到的,maven 插件将自动使用最新的可用 datanucleus 核心。为了防止这种使用:

    <plugin>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-maven-plugin</artifactId>
        <version>3.2.0-release</version>
        <configuration>
            <api>JDO</api>
            <props>${basedir}/datanucleus.properties</props>
            <verbose>true</verbose>
            <enhancerName>ASM</enhancerName>
        </configuration>
        <executions>
            <execution>
                <phase>process-classes</phase>
                <goals>
                    <goal>enhance</goal>
                </goals>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>org.datanucleus</groupId>
                <artifactId>datanucleus-core</artifactId>
                <version>3.1.3</version>
            </dependency>                    
        </dependencies>
    </plugin>
    

    增强器会起作用!所以不同的是谷歌使用了&lt;artifactId&gt;datanucleus-api-jdo&lt;/artifactId&gt; 这对我来说不是必需的,当然它并没有覆盖应该使用的 datanucleus-core 版本的选择。另请注意,从 3.2.0-m2 开始,该插件已从 maven-datanucleus-plugin 重命名为 datanucleus-maven-plugin。所以我也将其更改为使用官方 3.2.0-release。 此外,Google 还描述了使用 appengine-java-sdk-1.9.21/lib/opt/user/datanucleus/v2 中的 JAR 副本:

    • asm-4.0.jar
    • datanucleus-api-jdo-3.1.3.jar
    • datanucleus-api-jpa-3.1.3.jar
    • datanucleus-appengine-2.1.2.jar
    • datanucleus-core-3.1.3.jar
    • geronimo-jpa_2.0_spec-1.0.jar
    • jdo-api-3.0.1.jar jta-1.1.jar

    但由于我使用的不是 ant 而是 maven,因此我只需将此依赖项添加到 pom.xml 中,就可以将 JDO 与 DataNucleus 以及 Google 明确支持的版本一起使用:

    <dependency>
        <groupId>javax.jdo</groupId>
        <artifactId>jdo-api</artifactId>
        <version>3.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-core</artifactId>
        <version>3.1.3</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-api-jdo</artifactId>
        <version>3.1.3</version>
    </dependency>
    <dependency>
        <groupId>com.google.appengine.orm</groupId>
        <artifactId>datanucleus-appengine</artifactId>
        <version>2.1.2</version>
    </dependency>
    

    顺便说一句:我在 pom.xml 中发现了当前 appengine-skeleton-archetype 提供的另一个错误。 maven 目标“appengine 更新”失败,因为 appengine-maven-plugin 尝试上传我的应用程序,其版本设置为 1.9.21。这显然是使用的 GAE SDK 的版本,而不是我的应用程序的版本。它失败了,因为它违反了 GAE 允许的版本 ID 格式。修复方法是通过添加行 &lt;version&gt;${app.version}&lt;/version&gt; 来正确设置插件配置中的版本,如下所示:

    <plugin>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
        <version>${appengine.version}</version>
        <configuration>
            <enableJarClasses>false</enableJarClasses>
            <!-- Comment in the below snippet to bind to all IPs instead of just localhost -->
            <!-- address>0.0.0.0</address>
            <port>8080</port -->
            <!-- Comment in the below snippet to enable local debugging with a remote debugger
            like those included with Eclipse or IntelliJ -->
            <!-- jvmFlags>
              <jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
            </jvmFlags -->
            <version>${app.version}</version>
        </configuration>
    </plugin>
    

    玩得开心!

    【讨论】:

      猜你喜欢
      • 2013-11-10
      • 2012-05-26
      • 1970-01-01
      • 1970-01-01
      • 2013-07-02
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多