I've installed standalone Equinox and used it as run configuration in eclipse. Project uses EclipseLink as JPA and it's configured to use derby and mysql providers. These providers are packed into bundles and activated in OSGi container. When i run project from eclipse and activate my bundle, the JPA factory is created normally and project works fine.
But! When i run equinox standalone eclipselink can't load database connector driver. Drivers as is wrote are packed as bundles and activated.
I notice, the Eclipse uses the same configuration which i use to run Equinox standalone and the same set of bundles. And the same bundle internal tree the eclipse used to run.
As i understood java classpath isn't needed in OSGi container - there are bundles used. And they are imported in my plugin's manifest.mf.
What's the problem, i can't understand. Why the application cannot find driver classes?
Ok, i provide complete exception callstack for derby driver. It seems EL functions normal. For mysql driver the problem is the same, but callstack differs a bit. When i run the same program from eclipse it works right.
That's my configuration:
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>
That's how i run project:
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
That's the 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)
And finally the contents of derby.log file:
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)
I use that code to create entity factory:
mSystemEntities = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = mSystemEntities.createEntityManager();
And here's my 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>
I've found the solution. The Eclipse starts OSGi framework with org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar, but i try to load org.eclipse.osgi_3.8.100.v20120912-141032.jar. I think that framework without launcher doesnt support reflection cause classloader is missing. I'm not shure that the mechanism is of that kind but JPA works now and loads all drivers.