views:

1402

answers:

1

Hi there!

Currently I'm trying to execute some bundles using the capabilities of the EclipseStarter class. If I run my program directly from Eclipse the OSGi service bundle is loaded and I'm able to install and start other bundles.

But if I export my java program to a executable jar-file and run it from the command line the environment loads a bundle called "System Bundle [0]" instead of the OSGi service bundle. Every attempt to install a new bundle causes a Nullpointer-Exception.

Do I have to set some special configuration within the Framework properties to be able to use the OSGi environment from the jar file? Currently I'm only setting the following two values:

frameworkProperties.put("osgi.clean", "true");
frameworkProperties.put("osgi.console", "true");

Update:

I think my problem might have something to do with the used java classpath. If I add the Framework-Bundle to the classpath like this

java -classpath /home/markus/org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar:test.jar 
Starter.Starter

everything is working well:

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      org.eclipse.osgi_3.4.3.R34x_v20081215-1030

But if I only run the jar file I'm getting the following error log:

markus@markus-laptop:~/configuration$ cat 1244201504478.log !SESSION 2009-06-05 13:31:44.895 ----------------------------------------------- eclipse.buildId=unknown java.version=1.6.0_13 java.vendor=Sun Microsystems Inc. BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=de_DE Command-line arguments: -clean -console

!ENTRY org.eclipse.osgi 4 0 2009-06-05 13:31:44.897 !MESSAGE An unexpected runtime error has occurred. !STACK 0 java.lang.NullPointerException at org.eclipse.osgi.internal.baseadaptor.BaseStorage.readStateData(BaseStorage.java:743) at org.eclipse.osgi.internal.baseadaptor.BaseStorage.getStateManager(BaseStorage.java:698) at org.eclipse.osgi.baseadaptor.BaseAdaptor.getState(BaseAdaptor.java:390) at org.eclipse.core.runtime.adaptor.EclipseStarter$1.bundleChanged(EclipseStarter.java:307) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:1234) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:211) at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:141) at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1518) at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1469) at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:281) at org.eclipse.osgi.framework.internal.core.StartLevelManager.launch(StartLevelManager.java:247) at org.eclipse.osgi.framework.internal.core.SystemBundle.resume(SystemBundle.java:201) at org.eclipse.osgi.framework.internal.core.Framework.launch(Framework.java:644) at org.eclipse.osgi.framework.internal.core.OSGi.launch(OSGi.java:51) at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:313) at CanEmulator.OSGiFramework.run(OSGiFramework.java:119) at java.lang.Thread.run(Thread.java:619)

!ENTRY System Bundle 4 0 2009-06-05 13:31:44.898 !MESSAGE !STACK 0 java.lang.NullPointerException at org.eclipse.osgi.internal.baseadaptor.BaseStorage.readStateData(BaseStorage.java:743) at org.eclipse.osgi.internal.baseadaptor.BaseStorage.getStateManager(BaseStorage.java:698) at org.eclipse.osgi.baseadaptor.BaseAdaptor.getState(BaseAdaptor.java:390) at org.eclipse.core.runtime.adaptor.EclipseStarter$1.bundleChanged(EclipseStarter.java:307) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:1234) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:211) at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:141) at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1518) at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1469) at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:281) at org.eclipse.osgi.framework.internal.core.StartLevelManager.launch(StartLevelManager.java:247) at org.eclipse.osgi.framework.internal.core.SystemBundle.resume(SystemBundle.java:201) at org.eclipse.osgi.framework.internal.core.Framework.launch(Framework.java:644) at org.eclipse.osgi.framework.internal.core.OSGi.launch(OSGi.java:51) at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:313) at CanEmulator.OSGiFramework.run(OSGiFramework.java:119) at java.lang.Thread.run(Thread.java:619)

Currently I'm using the framework-jar-file as an external library within my Eclipse project. I think that somethings goes wrong when I export my project to an executable file ...

BR,

Markus

+2  A: 

Hi Markus,

I would also add the following properties

osgi.noShutdown=true

osgi.configuration.area= (path)
osgi.baseConfiguration.area= (path)
osgi.sharedConfiguration.area= (path)
osgi.instance.area= (path)
osgi.user.area= (path)

The first one tells Equinox not to stop. This is necessary if you are not creating an Eclipse application. The other ones are paths where various files should go. When you want to use the Console, just do

osgi.console=

No need for a value. If you put a number, that will be a telnet port where you can see the console.

Now, as for your bundles, you will ALWAYS see the System Bundle. That is OSGi itself. To add additional bundles, you need to install them. You can install them via the Console, or via config using:

osgi.bundles= (comman delim list of bundle paths)

You can install bundles programmatically using the System Bundle instance, which you can obtain from the EclipseStarter.

If these don't work, can you please upload a stack trace or the osgi log file (you might find the osgi log file in your working directory, or the "osgi.configuration.area"). It will be a file where the name is purely numeric.

omerkudat
Hi! After adding those parameters the framework isn't starting at all. If I run it now from the jar-file I'm getting a java.lang.NullPointerException. Therefore there is no osgi log file.
Markus