gpt4 book ai didi

java - DataNucleus、Maven、模式创建失败

转载 作者:行者123 更新时间:2023-11-30 11:08:02 24 4
gpt4 key购买 nike

我正在尝试使用 DataNucleus 和 MySQL 创建一个 Maven 项目。但是,当我尝试构建和 mvn datanucleus:schema-create项目,我失败了。我不明白为什么。

这是 persistence.xml类,它存在于 classes/META-INF 中构建项目的文件夹:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">

<!-- JDO tutorial "unit" -->
<persistence-unit name="Tutorial">
<class>hello.Counter</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.jdo.option.ConnectionURL" value="jdbc:mysql://localhost/glu" />
<property name="javax.jdo.option.ConnectionDriverName"
value="com.mysql.jdbc.Driver" />
<property name="javax.jdo.option.ConnectionUserName" value="root" />
<property name="javax.jdo.option.ConnectionPassword" value="root" />

<property name="datanucleus.schema.autoCreateAll" value="true" />
<property name="datanucleus.schema.validateTables" value="true" />
<property name="datanucleus.schema.validateConstraints"
value="true" />
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
</properties>
</persistence-unit>
</persistence>

这是 pom.xml我正在尝试使用。

<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>
<groupId>ru.sf0.one</groupId>
<artifactId>two</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>glu</name>


<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<!-- <version>1.2.0</version> -->
</dependency>


<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<!-- scope>runtime</scope -->
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>4.0.4</version>
</dependency>


<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<scope>runtime</scope>
<version>4.0.4</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-accessplatform-jdo-rdbms</artifactId>
<version>4.0.4</version>
<type>pom</type>
</dependency>


</dependencies>


<build>

<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>3.2</version> -->
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>4.0.0-release</version>


<configuration>
<api>JDO</api>
<persistenceUnitName>Tutorial</persistenceUnitName>
<log4jConfiguration>${basedir}/src/main/resources/log4j.properties</log4jConfiguration>
<verbose>false</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>


</plugins>
</build>

<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>

我得到的错误是:

~>2015-02-23 00:26:55 DEBUG MetaData:58 - Class "hello.Counter" field "count" : Adding Meta-Data for field since it didnt appear in the Meta-Data definition.
~>2015-02-23 00:26:55 DEBUG MetaData:58 - Initialising all MetaData ...
~>2015-02-23 00:26:55 DEBUG MetaData:58 - Class "hello.Counter" : Initialising Meta-Data
~>2015-02-23 00:26:55 DEBUG MetaData:58 - MetaData Management : Load of Metadata complete
~>2015-02-23 00:26:55 DEBUG Datastore:58 - Creating StoreManager for datastore
~>2015-02-23 00:26:55 ERROR Datastore:125 - Exception thrown creating StoreManager. See the nested exception
There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType"
org.datanucleus.exceptions.NucleusUserException: There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType"
at org.datanucleus.NucleusContextHelper.createStoreManagerForProperties(NucleusContextHelper.java:223)
at org.datanucleus.PersistenceNucleusContextImpl.initialise(PersistenceNucleusContextImpl.java:433)
at org.datanucleus.store.schema.SchemaTool.getNucleusContextForMode(SchemaTool.java:693)
at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:286)
~>2015-02-23 00:26:55 ERROR SchemaTool:125 - Error creating NucleusContext
There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType"
org.datanucleus.exceptions.NucleusUserException: There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType"
at org.datanucleus.NucleusContextHelper.createStoreManagerForProperties(NucleusContextHelper.java:223)
at org.datanucleus.PersistenceNucleusContextImpl.initialise(PersistenceNucleusContextImpl.java:433)
at org.datanucleus.store.schema.SchemaTool.getNucleusContextForMode(SchemaTool.java:693)
at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:286)
An error was encountered creating a PersistenceManagerFactory : There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType" - please consult the log for more information.

UPD 如果我删除 <scope>runtime</scope>来自 datanucleus-rdbms 的限制,我收到以下错误:

~>2015-02-23 12:07:34 DEBUG MetaData:58 - Class "hello.Counter" field "count" : Adding Meta-Data for field since it didnt appear in the Meta-Data definition.
~>2015-02-23 12:07:34 DEBUG MetaData:58 - Initialising all MetaData ...
~>2015-02-23 12:07:34 DEBUG MetaData:58 - Class "hello.Counter" : Initialising Meta-Data
~>2015-02-23 12:07:34 DEBUG MetaData:58 - MetaData Management : Load of Metadata complete
~>2015-02-23 12:07:34 DEBUG Datastore:58 - Creating StoreManager for datastore
~>2015-02-23 12:07:34 ERROR Datastore:125 - Exception thrown creating StoreManager. See the nested exception
Error creating transactional connection factory
org.datanucleus.exceptions.NucleusException: Error creating transactional connection factory
at org.datanucleus.store.AbstractStoreManager.registerConnectionFactory(AbstractStoreManager.java:219)
at org.datanucleus.store.AbstractStoreManager.<init>(AbstractStoreManager.java:163)
at org.datanucleus.store.rdbms.RDBMSStoreManager.<init>(RDBMSStoreManager.java:288)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:606)
at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:301)
at org.datanucleus.NucleusContextHelper.createStoreManagerForProperties(NucleusContextHelper.java:193)
at org.datanucleus.PersistenceNucleusContextImpl.initialise(PersistenceNucleusContextImpl.java:433)
at org.datanucleus.store.schema.SchemaTool.getNucleusContextForMode(SchemaTool.java:693)
at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:286)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:606)
at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:330)
at org.datanucleus.store.AbstractStoreManager.registerConnectionFactory(AbstractStoreManager.java:205)
... 12 more
Caused by: java.lang.NullPointerException
at org.datanucleus.store.rdbms.ConnectionFactoryImpl.initialiseDataSources(ConnectionFactoryImpl.java:110)
at org.datanucleus.store.rdbms.ConnectionFactoryImpl.<init>(ConnectionFactoryImpl.java:82)
... 19 more
Nested Throwables StackTrace:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:606)
at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:330)
at org.datanucleus.store.AbstractStoreManager.registerConnectionFactory(AbstractStoreManager.java:205)
at org.datanucleus.store.AbstractStoreManager.<init>(AbstractStoreManager.java:163)
at org.datanucleus.store.rdbms.RDBMSStoreManager.<init>(RDBMSStoreManager.java:288)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:606)
at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:301)
at org.datanucleus.NucleusContextHelper.createStoreManagerForProperties(NucleusContextHelper.java:193)
at org.datanucleus.PersistenceNucleusContextImpl.initialise(PersistenceNucleusContextImpl.java:433)
at org.datanucleus.store.schema.SchemaTool.getNucleusContextForMode(SchemaTool.java:693)
at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:286)
Caused by: java.lang.NullPointerException
at org.datanucleus.store.rdbms.ConnectionFactoryImpl.initialiseDataSources(ConnectionFactoryImpl.java:110)
at org.datanucleus.store.rdbms.ConnectionFactoryImpl.<init>(ConnectionFactoryImpl.java:82)
... 19 more

最佳答案

错误消息请确保您已将相关的 DataNucleus 存储插件放入您的 CLASSPATH 中,说明了您真正需要了解的所有信息。 datanucleus-rdbms 插件不在 CLASSPATH 中……您对 runtime

的范围限制

关于java - DataNucleus、Maven、模式创建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28658794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com