Hello, everyone!

I am unable to start a OSGI bundle. I'm using Apache Felix and this is my bundle:

1) Activator.java

package Example2;

import java.util.Properties;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import Example2.Service.IDictionaryService;


/**
 * This is the bundle.
 * @author Pierre-Alexandre
 *
 */
public class Activator implements BundleActivator
{
	public Activator()
	{
		
	}
	
	@Override
	public void start(BundleContext context) throws Exception 
	{
		Properties props = new Properties();
		props.put("Language", "Hockey");
		context.registerService(IDictionaryService.class.getName(), new HockeyDictionary(), props);
	}

	@Override
	public void stop(BundleContext context) throws Exception
	{
	}

	/**
	 * This a private implementation of the IDictionaryService.
	 * @author Pierre-Alexandre
	 */
	private static class HockeyDictionary implements IDictionaryService
	{
		private String[] m_dictionary = { "kovalchuk", "crosby", "ovechkin", "malkin" };
		
		//-----------------------------------------------
		public boolean checkWord(String word) 
		{	
			for (String dictWord : m_dictionary)
			{
				if (word.equals(dictWord))
				{
					return true;
				}
			}
			
			return false;
		}
		
	}
}

2) IDictionaryService.java

package Example2.Service;

public interface IDictionaryService 
{
	public boolean checkWord(String word);
}

This is the manifest file that I'm using (it has a blank line at the end):

Bundle-Name: Hockey dictionary
Bundle-Description: A bundle that registers a hockey dictionary service
Bundle-Vendor: Apache Felix
Bundle-Version: 1.0.0
Bundle-Activator: Example2.Activator
Export-Package: Example2.Service
Import-Package: org.osgi.framework


Here are the commands that I enter:

This creates the .class files.

PS C:\Users\Pierre-Alexandre\workspace\ApacheFelixExample\src\Example2> javac -classpath '..\..\..\..\Documents\Études\U
niversité\Automne 2010\IFT697 - Projet\OSGI\felix-framework-3.0.2\bin\felix.jar' .\Activator.java .\Service\IDictionaryS
ervice.java

This creates the jar for launching the bundle.

PS C:\Users\Pierre-Alexandre\workspace\ApacheFelixExample\src\Example2> jar cfm example2.jar ./Service/manifest.mf './Ac
tivator$1.class' './Activator$HockeyDictionary.class' './Activator.class' ./Service/IDictionaryService.class

This installs and starts the bundle.

g! start file:/C:/Users/Pierre-Alexandre/workspace/ApacheFelixExample/src/Example2/example2.jar

This is the output I have:

org.osgi.framework.BundleException: Not found: Example2.Activator
at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3657)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1812)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1734)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:905)
at org.apache.felix.gogo.command.Basic.start(Basic.java:758)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.gogo.runtime.Reflective.method(Reflective.java:136)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:421)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:335)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:184)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:121)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:78)
at org.apache.felix.gogo.shell.Console.run(Console.java:62)
at org.apache.felix.gogo.shell.Shell.console(Shell.java:197)
at org.apache.felix.gogo.shell.Shell.gosh(Shell.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.gogo.runtime.Reflective.method(Reflective.java:136)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:421)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:335)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:184)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:121)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:78)
at org.apache.felix.gogo.shell.Activator.run(Activator.java:72)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: Example2.Activator
at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:772)
at org.apache.felix.framework.ModuleImpl.access$200(ModuleImpl.java:73)
at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1690)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:634)
at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3653)
... 33 more
java.lang.ClassNotFoundException: Example2.Activator

After hours of debugging, I'm out of ideas. Is there someone who can point me what's wrong?

Thanks.

Edit: Note that all the paths are good. I have double and triple-checked their validity.

Recommended Answers

All 3 Replies

I'm guessing its the manifest. lots out there if you google bunde-activator.

saw this:

Bundle-Activator: class-name

where class-name is a fully qualified Java classname

maybe your name isn't quite doing it with package.classname you have.

Mike

I have verified the Bundle-Activator line in manifest.mf and unfortunately, it is ok. My Activator.class is in the Example2 package, according to the code I've posted.

I was thinking of a different loading order for .class files to see it if's the class loading for jar construction that, maybe, does not include the Activator class. I've tried to change the order and it does not work.

So, i'm still unable to make it work. Any other ideas?

I finally solved my problem: the jar I was creating did not have a directory for the package inside. So, I enter this command:

PS C:\Users\Pierre-Alexandre\workspace\ApacheFelixExample\src> jar cfm ServiceExpositionExample.jar ServiceExpositionExa
mple\manifest.mf .\ServiceExpositionExample\*.class

And it works! Hope that this solution can help others.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.