[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-core-dev] Ask for example about starting eclipse's osgi
|
Hi,
Is anyone here could give me an short example of using eclipse's osgi
implementation without eclipse? or where can I find needed info?
There's no articles on the eclipse site on this topic :(
I thought the way I use eclipse's osgi should be simplely add
org.eclipse.core.runtime.jar and org.eclipse.osgi.jar to
classpath and coding as follows.
------------------------------------
package com.mabo.foo;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.eclipse.osgi.framework.internal.core.OSGi;
import org.eclipse.osgi.framework.internal.defaultadaptor.DefaultAdaptor;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
public class FooStarter {
private static final String BUNDLE_URL = "file:/e:/temp/foobundle.jar";
private FrameworkAdaptor adaptor;
private OSGi osgi;
private BundleContext context;
public FooStarter(String[] args) {
adaptor = new DefaultAdaptor(args);
osgi = new OSGi(adaptor);
context = osgi.getBundleContext();
}
public void start() {
this.osgi.launch();
installBundle();
printInstalledBundles();
startBundles();
}
private void startBundles() {
Bundle[] bundles = context.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
try {
bundle.start();
} catch (BundleException e) {
System.err.println("Error during starting...");
e.printStackTrace();
}
}
}
private void installBundle() {
try {
context.installBundle(BUNDLE_URL);
} catch (BundleException e) {
System.err.println("Error during installing...");
e.printStackTrace();
}
}
private void printInstalledBundles() {
System.out.println("print installed bundles...");
Bundle[] installed = context.getBundles();
System.out.println(installed.length);
for (int idx = 0; idx < installed.length; idx++) {
System.out.println("Symb name = "
+ installed[idx].getSymbolicName());
}
System.out.println("done");
}
public static void main(String[] args) {
FooStarter starter = new FooStarter(args);
starter.start();
}
} ///:~
--------------------------------------------------------------------
Is my code below correctly?
Where foobundle was a very simple osgi bundle:
--------------------------------------------------------------------
package com.mabo.foo;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
/**
* The main plugin class to be used in the desktop.
*/
public class FooPlugin extends Plugin {
//The shared instance.
private static FooPlugin plugin;
/**
* The constructor.
*/
public FooPlugin() {
plugin = this;
}
/**
* This method is called upon plug-in activation
*/
public void start(BundleContext context) throws Exception {
super.start(context);
System.out.println("Hello, Eclipse-OSGi
impl!");
}
/**
* This method is called when the plug-in is stopped
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
System.out.println("Bye-bye,
Eclipse-OSGi impl!");
plugin = null;
}
/**
* Returns the shared instance.
*/
public static FooPlugin getDefault() {
return plugin;
}
}
--------------------------------------------------------------------
But got error msg as follows: (the bundle did get installed! but can't
be resolved)
--------------------------------------------------------------------
print installed bundles...
2
Symb name = system.bundle
Symb name = com.mabo.foo
done
Error during starting...
org.osgi.framework.BundleException: The bundle could not be resolved.
Reason: missing required bundle org.eclipse.core.runtime_0.0.0
at
org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:296)
at
org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:266)
at com.mabo.foo.FooStarter.startBundles(FooStarter.java:36)
at com.mabo.foo.FooStarter.start(FooStarter.java:28)
at com.mabo.foo.FooStarter.main(FooStarter.java:66)
--------------------------------------------------------------------
I modified the config.ini as follows:
osgi.bundles=org.eclipse.core.runtime_3.1.0@2:start,
org.eclipse.update.configurator_3.1.0@3:start
but eclipse can't be started, the error message in log file are:
--------------------------------------------------------------------
!MESSAGE Bundle org.eclipse.core.runtime_3.1.0@2:start not found.
...
!MESSAGE Bundle org.eclipse.update.configurator_3.1.0@3:start not found.
...
!MESSAGE Bundle update@plugins/org.eclipse.ant.core_3.1.0.jar [5] was
not resolved.
...
What's the matter?