我已经安装了独立的Equinox并在eclipse中将其用作运行配置。 Project使用EclipseLink作为JPA,并将其配置为使用derby和mysql提供程序。这些提供程序打包成捆绑并在OSGi容器中激活。当我从eclipse运行项目并激活我的包时,JPA工厂正常创建,项目工作正常。
但是!当我运行equinox独立eclipselink无法加载数据库连接器驱动程序。写入的驱动程序打包为捆绑并激活。
我注意到,Eclipse使用了我用来运行Equinox独立版和相同捆绑包的相同配置。和eclipse过去运行的捆绑内部树相同。
据我所知,OSGi容器中不需要java类路径 - 使用了捆绑包。它们是在我的插件manifest.mf中导入的。
问题是什么,我无法理解。为什么应用程序找不到驱动程序类?
好的,我为德比驱动程序提供了完整的异常调用。看来EL功能正常。对于mysql驱动程序问题是一样的,但callstack有点不同。当我从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
那就是callstack:
[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>
答案 0 :(得分:0)
你还没有提供代码和异常,所以我想你做了以下的
如果您使用JDBC并通过
创建连接connection = DriverManager.getConnection(connectionUrl, username, password);
使用sole语句然后在osgi中通常会抛出异常而你不会得到任何驱动程序和驱动程序为null。
但如果你用过
Class.forName(driver);
在创建连接osgi之前,可以在运行时加载驱动程序,
OSGi中的反思有点正统。
答案 1 :(得分:0)
我找到了解决方案。 Eclipse使用org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar启动OSGi框架,但我尝试加载org.eclipse.osgi_3.8.100.v20120912-141032.jar。我认为没有启动器的框架不支持反射导致类加载器丢失。我并不感觉机制是那种机制,但JPA现在可以工作并加载所有驱动程序。