java.lang.ClassNotFoundException:找不到org.eclipse.persistence.internal.jpa.rs.metadata.model.Link

时间:2016-07-29 03:19:33

标签: maven jpa osgi blueprint-osgi

我正在尝试在OSGi包中注入EntityManager但我收到错误 -

[EL Severe]: 2016-07-29 08:34:19.029--ServerSession(1711371450)--java.lang.NoClassDefFoundError: org/eclipse/persistence/internal/jpa/rs/metadata/model/Link
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getDeclaredMethods(Unknown Source)
        at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getDeclaredMethods(PrivilegedAccessHelper.java:339)
        at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListenerMetadata.getDeclaredMethods(EntityListenerMetadata.java:249)
        at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityClassListenerMetadata.process(EntityClassListenerMetadata.java:89)
        at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.processListeners(EntityAccessor.java:1226)
        at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.addEntityListeners(MetadataProcessor.java:140)
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:634)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:305)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:310)
        at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.aries.jpa.container.impl.QuiesceEMFHandler.invoke(QuiesceEMFHandler.java:55)
        at com.sun.proxy.$Proxy37.createEntityManager(Unknown Source)
        at org.apache.aries.jpa.container.context.transaction.impl.JTAEntityManagerHandler.getPersistenceContext(JTAEntityManagerHandler.java:125)
        at org.apache.aries.jpa.container.context.transaction.impl.JTAEntityManagerHandler.invoke(JTAEntityManagerHandler.java:187)
        at com.sun.proxy.$Proxy38.contains(Unknown Source)
        at icom.leader.application.entitymanager.EventDao.insert(EventDao.java:33)
        at icom.leader.application.entitymanager.EventDao.doExecute(EventDao.java:28)
        at org.apache.karaf.shell.console.AbstractAction.execute(AbstractAction.java:34)
        at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:41)
        at org.apache.karaf.shell.commands.basic.AbstractCommand.execute(AbstractCommand.java:34)
        at org.apache.karaf.shell.compat.CommandTracker$1.execute(CommandTracker.java:109)
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)
        at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
        at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:268)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.persistence.internal.jpa.rs.metadata.model.Link not found by com.knorrbremse.icom.leader.application [313]
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1558)
        at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1998)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 37 more

可能是什么问题? 下面是我的文件 -

pom.xml:

    <dependency>
        <groupId>com.knorrbremse.icom</groupId>
        <version>2.0.0-SNAPSHOT</version>
        <artifactId>icom.leader.platfrom</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink -->
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.core</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4-1200-jdbc41</version>
    </dependency>
    <dependency>
        <groupId>org.apache.karaf.shell</groupId>
        <artifactId>org.apache.karaf.shell.console</artifactId>
        <version>4.0.5</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.transaction/jta -->
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
    </dependency>

blueprint.xml:

<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
    xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.2.0"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"
    default-activation="eager">

    <bean id="icomOffboardDataSource" class="org.apache.commons.dbcp2.BasicDataSource"
        destroy-method="close">
        <property name="url"
            value="jdbc:postgresql://localhost:5432/enetity_manager" />
        <property name="username" value="postgres" />
        <property name="password" value="kbroot" />
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="initialSize" value="10" />
        <property name="maxTotal" value="50" />
        <property name="maxIdle" value="20" />
    </bean>

    <bean id="icomOffboardXADataSource" class="org.apache.commons.dbcp2.managed.BasicManagedDataSource"
        destroy-method="close">
        <property name="url"
            value="jdbc:postgresql://localhost:5432/enetity_manager" />
        <property name="username" value="postgres" />
        <property name="password" value="kbroot" />
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="initialSize" value="10" />
        <property name="maxTotal" value="50" />
        <property name="maxIdle" value="20" />
        <property name="transactionManager" ref="transactionManager" />

    </bean>

    <service ref="icomOffboardXADataSource" interface="javax.sql.DataSource">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/icomOffboardXADataSource" />
            <entry key="icom.isXa" value="true" />
        </service-properties>
    </service>

    <service ref="icomOffboardDataSource" interface="javax.sql.DataSource">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/icomOffboardDataSource" />
            <entry key="icom.isXa" value="false" />
        </service-properties>
    </service>


    <bean id="eventDao" class="icom.leader.application.entitymanager.EventDao">
    </bean>
    <service ref="eventDao" interface="icom.leader.application.entityif.EventDaoIF" />

    <bean id="entityManagerService" class="icom.leader.application.entitymanager.EntityManagerService">
        <jpa:context unitname="icomentitymanager" property="entityManager" />
        <tx:transaction method="*" value="Required" />
    </bean>
    <service ref="entityManagerService" interface="icom.leader.entitymanager.EntityManagerIf" />

    <reference id="entityManager" activation="eager" availability="mandatory"
        interface="icom.leader.entitymanager.EntityManagerIf">
        <reference-listener bind-method="bindDBManagerService"
            unbind-method="unbindDBManagerService">
            <ref component-id="eventDao" />
        </reference-listener>
    </reference>


    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
        <command name="leader-test/create-sample-data1">
            <action class="icom.leader.application.entitymanager.EventDao">
            </action>
        </command>
    </command-bundle>
    <reference id="transactionManager" interface="javax.transaction.TransactionManager" />

persistance.xml:

    <persistence-unit name="icomentitymanager" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/icomOffboardXADataSource)
        </jta-data-source>
        <non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/icomOffboardDataSource)
        </non-jta-data-source>

        <class>icom.leader.application.entitymanager.Event</class>
        <class>icom.leader.platform.entities.VehicleType</class>
        <class>icom.leader.platform.entities.Vehicle</class>


        <!-- <mapping-file>META-INF/leader_orm.xml</mapping-file> -->
        <properties>
            <property name="eclipselink.ddl-generation" value="create-tables" />  

            <property name="eclipselink.weaving" value="true"/>
            <property name="eclipselink.target-database" value="PostgreSQL"/>
            <property name="eclipselink.target-server"
                      value="org.apache.aries.jpa.eclipselink.adapter.platform.OSGiTSServer"/>
            <!--<property name="eclipselink.ddl-generation" value="none"/>-->
            <!--<property name="eclipselink.ddl-generation.output-mode" value="database"/>-->

            <!-- for file creation -->
            <property name="eclipselink.ddl-generation" value="create-tables"/>
            <property name="eclipselink.ddl-generation.output-mode" value="sql-script"/>
            <property name="eclipselink.application-location" value="data/tmp/"/>
            <property name="eclipselink.create-ddl-jdbc-file-name" value="application_schema.sql"/>


        </properties>

    </persistence-unit>

实施档案:

public class EventDao extends OsgiCommandSupport implements EventDaoIF {

    private static EntityManager entityManager;

    @Override
    protected Object doExecute() throws Exception {

        insert();
        return ".. done";
    }

    void insert(){
        if (entityManager.contains(Event.class)){
            System.out.println("true");
        } else {
            System.out.println("false");
        }
    }


    public void bindDBManagerService(EntityManagerIf entityManager, Map props) {

        EventDao.entityManager=entityManager.getEntityManager();
    }


    public void unbindDBManagerService(EntityManagerIf entityManager, Map props){
        EventDao.entityManager=entityManager.getEntityManager();
    }

当我尝试使用entityManager的任何方法时,它会给出上述错误。

1 个答案:

答案 0 :(得分:0)

我猜它是从冲突罐中发生的,你应该使用其中一个,如果没有尝试2.6.0以上的版本。我猜这两个库可能在不同的上下文中使用相同

<dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.6.0</version>
    </dependency>

 <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.core</artifactId>
        <version>2.6.0</version>
    </dependency>