DataNucleus,Maven,架构创建失败

时间:2015-02-22 14:14:04

标签: java maven datanucleus

我正在尝试使用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

1 个答案:

答案 0 :(得分:1)

错误消息Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH表示您真正需要知道的。 datanucleus-rdbms插件不在CLASSPATH ... runtime的范围限制