0

我已经安装了独立的 Equinox 并将其用作 eclipse 中的运行配置。项目使用 EclipseLink 作为 JPA,并配置为使用 derby 和 mysql 提供程序。这些提供程序打包成包并在 OSGi 容器中激活。当我从 Eclipse 运行项目并激活我的包时,JPA 工厂正常创建并且项目工作正常。

但!当我运行 Equinox 独立 eclipselink 无法加载数据库连接器驱动程序。所写的驱动程序被打包为捆绑包并激活。

我注意到,Eclipse 使用与我用于独立运行 Equinox 的相同配置和相同的捆绑包集。和 eclipse 用来运行的同一个包内部树。

据我了解,OSGi 容器中不需要 java 类路径 - 使用了捆绑包。它们被导入到我插件的 manifest.mf 中。

什么问题,看不懂。为什么应用程序找不到驱动程序类?


好的,我为 derby 驱动程序提供了完整的异常调用堆栈。看来EL功能正常。对于 mysql 驱动程序,问题是相同的,但调用堆栈有所不同。当我从 Eclipse 运行相同的程序时,它可以正常工作。

这是我的配置:

id      State       Bundle
0       ACTIVE      org.eclipse.osgi_3.8.100.v20120912-141032
                    Fragments=724, 726, 728
694     ACTIVE      org.eclipse.equinox.simpleconfigurator_1.0.400.v20120828-033
824
695     ACTIVE      com.ibm.icu.base_4.4.2.v20110831
696     ACTIVE      com.mysql.jdbc_5.8.0
697     ACTIVE      javax.el_2.2.0.v201108011116
698     ACTIVE      javax.persistence_2.0.4.v201112161009
699     ACTIVE      javax.servlet_3.0.0.v201112011016
700     ACTIVE      javax.servlet.jsp_2.2.0.v201112011158
702     ACTIVE      org.apache.felix.gogo.command_0.8.0.v201108120515
703     ACTIVE      org.apache.felix.gogo.runtime_0.8.0.v201108120515
704     ACTIVE      org.apache.felix.gogo.shell_0.8.0.v201110170705
705     ACTIVE      org.eclipse.core.commands_3.6.1.v20120521-2329
706     ACTIVE      org.eclipse.core.contenttype_3.4.200.v20120523-2004
707     ACTIVE      org.eclipse.core.databinding_1.4.1.v20120521-2329
708     ACTIVE      org.eclipse.core.databinding.observable_1.4.1.v20120521-2329
709     ACTIVE      org.eclipse.core.databinding.property_1.4.100.v20120523-1955
710     ACTIVE      org.eclipse.core.expressions_3.4.401.v20120627-124442
711     ACTIVE      org.eclipse.core.jobs_3.5.300.v20120622-204750
712     ACTIVE      org.eclipse.core.runtime_3.8.0.v20120521-2346
713     ACTIVE      org.eclipse.equinox.app_1.3.100.v20120522-1841
714     ACTIVE      org.eclipse.equinox.common_3.6.100.v20120522-1841
715     ACTIVE      org.eclipse.equinox.console_1.0.0.v20120522-1841
716     ACTIVE      org.eclipse.equinox.ds_1.4.0.v20120522-1841
717     ACTIVE      org.eclipse.equinox.frameworkadmin_2.0.100.v20120606-175127
718     ACTIVE      org.eclipse.equinox.frameworkadmin.equinox_1.0.400.v20120428-0117
719     ACTIVE      org.eclipse.equinox.http.jetty_3.0.0.v20120522-1841
720     ACTIVE      org.eclipse.equinox.http.registry_1.1.200.v20120912-125810
721     ACTIVE      org.eclipse.equinox.http.servlet_1.1.300.v20120912-125810
722     ACTIVE      org.eclipse.equinox.preferences_3.5.0.v20120918-182152
723     ACTIVE      org.eclipse.equinox.registry_3.5.300.v20120731-134527
724     RESOLVED    org.eclipse.equinox.servletbridge.extensionbundle_1.2.100.v20120522-2049
                    Master=0
725     ACTIVE      org.eclipse.equinox.simpleconfigurator.manipulator_2.0.0.v20110808-1657
726     RESOLVED    org.eclipse.equinox.transforms.hook_1.0.400.v20120522-2049
                    Master=0
727     ACTIVE      org.eclipse.equinox.util_1.0.400.v20120917-191249
728     RESOLVED    org.eclipse.equinox.weaving.hook_1.0.200.v20120524-1707
                    Master=0
729     ACTIVE      org.eclipse.help_3.6.0.v20120521-2344
730     ACTIVE      org.eclipse.jetty.continuation_8.1.3.v20120522
731     ACTIVE      org.eclipse.jetty.http_8.1.3.v20120522
732     ACTIVE      org.eclipse.jetty.io_8.1.3.v20120522
733     ACTIVE      org.eclipse.jetty.security_8.1.3.v20120522
734     ACTIVE      org.eclipse.jetty.server_8.1.3.v20120522
735     ACTIVE      org.eclipse.jetty.servlet_8.1.3.v20120522
736     ACTIVE      org.eclipse.jetty.util_8.1.3.v20120522
737     ACTIVE      org.eclipse.osgi.services_3.3.100.v20120522-1822
738     ACTIVE      org.eclipse.osgi.util_3.2.300.v20120912-140840
739     ACTIVE      org.eclipse.persistence.asm_3.3.1.v201206041142
740     ACTIVE      org.eclipse.persistence.core_2.4.0.v20120608-r11652
741     ACTIVE      org.eclipse.persistence.jpa_2.4.0.v20120608-r11652
742     ACTIVE      org.eclipse.persistence.jpa.osgi_2.4.0.v20120608-r11652
743     ACTIVE      org.eclipse.rap.jface_2.0.0.20120821-1934
744     ACTIVE      org.eclipse.rap.jface.databinding_2.0.0.20120821-1934
745     ACTIVE      org.eclipse.rap.rwt_2.0.0.20120821-1934
746     ACTIVE      org.eclipse.rap.rwt.osgi_2.0.0.20120821-1934
747     ACTIVE      org.eclipse.rap.ui_2.0.0.20120821-1934
748     ACTIVE      org.eclipse.rap.ui.workbench_1.5.100.20120821-1934
749     ACTIVE      ru.futurelink.testrap_1.0.0.qualifier
750     ACTIVE      org.apache.derby_1.0.0
osgi>

这就是我运行项目的方式:

java -Declipse.ignoreApp=true -Dosgi.noShutdown=true -cp C:/Projects/ru.futurelink.testrap/lib/eclipselink.jar -cp C:/Projects/ru.futurelink.testrap/lib/javax.persistence_1.0.0.jar -cp C:/Projects/ru.futurelink.testrap/lib/derby.jar -cp C:/Projects/ru.futurelink.testrap/lib/mysql-connector-java-5.0.8-bin.jar -jar plugins\org.eclipse.osgi_3.8.100.v20120912-141032.jar  -dev file:C:/Equinox/plugins/configuration/dev.properties -os win32 -ws win32 -arch x86_64 -nl ru_RU -console -consoleLog

那是调用堆栈:

[EL Info]: 2012-09-30 20:59:57.778--ServerSession(333070563)--EclipseLink, version: Eclipse Persistence Services - 2.4.0.v20120608-r11652
[EL Severe]: ejb: 2012-09-30 20:59:58.213--ServerSession(333070563)--java.lang.NullPointerException
2012-09-30 20:59:58.213:WARN:oejs.ServletHandler:ERROR:  /examples
java.lang.reflect.UndeclaredThrowableException
    at $Proxy0.createEntityManager(Unknown Source)
    at ru.futurelink.moneyorganizer.data.MODatabase.<init>(MODatabase.java:13)
    at ru.futurelink.moneyorganizer.ApplicationEntryPoint.createUI(ApplicationEntryPoint.java:22)
    at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:177)
    at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:289)
    at java.lang.Thread.run(Thread.java:722)
    at org.eclipse.rap.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)
Caused by:
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.persistence.jpa.osgi.EMFServiceProxyHandler.invoke(EMFServiceProxyHandler.java:77)
    at $Proxy0.createEntityManager(Unknown Source)
    at ru.futurelink.moneyorganizer.data.MODatabase.<init>(MODatabase.java:13)
    at ru.futurelink.moneyorganizer.ApplicationEntryPoint.createUI(ApplicationEntryPoint.java:22)
    at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:177)
    at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:289)
    at java.lang.Thread.run(Thread.java:722)
    at org.eclipse.rap.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)
Caused by:
javax.persistence.PersistenceException: java.lang.NullPointerException
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:602)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:186)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:278)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:282)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.persistence.jpa.osgi.EMFServiceProxyHandler.invoke(EMFServiceProxyHandler.java:77)
    at $Proxy0.createEntityManager(Unknown Source)
    at ru.futurelink.moneyorganizer.data.MODatabase.<init>(MODatabase.java:13)
    at ru.futurelink.moneyorganizer.ApplicationEntryPoint.createUI(ApplicationEntryPoint.java:22)
    at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:177)
    at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:289)
    at java.lang.Thread.run(Thread.java:722)
    at org.eclipse.rap.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)
Caused by:
java.lang.NullPointerException
    at org.apache.derby.jdbc.EmbeddedDriver.connect(Unknown Source)
    at org.eclipse.persistence.sessions.DefaultConnector.directConnect(DefaultConnector.java:165)
    at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:117)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:685)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:213)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:542)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:186)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:278)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:282)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.persistence.jpa.osgi.EMFServiceProxyHandler.invoke(EMFServiceProxyHandler.java:77)
    at $Proxy0.createEntityManager(Unknown Source)
    at ru.futurelink.moneyorganizer.data.MODatabase.<init>(MODatabase.java:13)
    at ru.futurelink.moneyorganizer.ApplicationEntryPoint.createUI(ApplicationEntryPoint.java:22)
    at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:177)
    at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:289)
    at java.lang.Thread.run(Thread.java:722)
    at org.eclipse.rap.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)

最后是 derby.log 文件的内容:

Sun Sep 30 20:59:58 GMT+11:00 2012 Thread[UIThread [1ix4et52sn4jvzywdjyip1m3v],5,main] Class org.apache.derby.jdbc.Driver40 java.lang.NoClassDefFoundError: javax/sql/XAConnection, module ignored.
Sun Sep 30 20:59:58 GMT+11:00 2012 Thread[UIThread [1ix4et52sn4jvzywdjyip1m3v],5,main] Class org.apache.derby.jdbc.Driver30 java.lang.NoClassDefFoundError: javax/sql/XAConnection, module ignored.
Sun Sep 30 20:59:58 GMT+11:00 2012 Thread[UIThread [1ix4et52sn4jvzywdjyip1m3v],5,main] Class org.apache.derby.impl.services.jmx.JMXManagementService java.lang.NoClassDefFoundError: javax/management/JMException, module ignored.
Sun Sep 30 20:59:58 GMT+11:00 2012 Thread[UIThread [1ix4et52sn4jvzywdjyip1m3v],5,main] Cleanup action starting
ERROR XBM02: Startup failed due to missing functionality for org.apache.derby.jdbc.InternalDriver. Please ensure your classpath includes the correct Derby software.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.missingImplementation(Unknown Source)
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startServices(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.runWithState(Unknown Source)
at org.apache.derby.impl.services.monitor.FileMonitor.<init>(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.startMonitor(Unknown Source)
at org.apache.derby.iapi.jdbc.JDBCBoot.boot(Unknown Source)
at org.apache.derby.jdbc.EmbeddedDriver.boot(Unknown Source)
at org.apache.derby.jdbc.EmbeddedDriver.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)

我使用该代码创建实体工厂:

mSystemEntities = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = mSystemEntities.createEntityManager();

这是我的persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">

<persistence-unit name="prov" transaction-type="RESOURCE_LOCAL">      
    <class>ru.futurelink.moneyorganizer.data.MOUserEntity</class>
    <properties>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
      <property name="javax.persistence.jdbc.url" value="jdbc:derby:/sampledb;create=true" />

      <!-- EclipseLink should create the database schema automatically -->
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
      <property name="eclipselink.ddl-generation.output-mode" value="database" />
    </properties>

  </persistence-unit>  
</persistence> 
4

2 回答 2

0

我找到了解决方案。Eclipse 使用 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar 启动 OSGi 框架,但我尝试加载 org.eclipse.osgi_3.8.100.v20120912-141032.jar。我认为没有启动器的框架不支持反射导致类加载器丢失。我不确定该机制是否属于这种机制,但 JPA 现在可以工作并加载所有驱动程序。

于 2012-10-03T12:16:05.057 回答
0

好吧,您还没有提供代码和异常,所以我想您在执行以下操作

如果您使用 JDBC 并通过

connection = DriverManager.getConnection(connectionUrl, username, password);

使用唯一的语句然后在 osgi 中它通常会引发异常并且您不会得到任何驱动程序并且驱动程序为空。

但如果你用过

Class.forName(driver);

在创建连接之前 osgi 能够在运行时加载驱动程序,

OSGi 中的反射有点正统。

于 2012-09-27T05:19:53.890 回答