On 9/27/11 4:10 AM, Antonello Calabrò wrote:
Dear Rob,
thank you so much for the suggestion.
I tried unsuccessfully to add each import for activemq.. :(
So, I tried *successfully* to switch class loader into my application using

*
Thread.currentThread().setContextClassLoader(org.apache.activemq.jndi.ActiveMQInitialContextFactory.class.getClassLoader());
*

and seems to work.. partially :) cause when loading other resources/classes,
the application crashes when it tries to load drools engine at:

Class: ComplexEventProcessorImpl - Operation: Reading knowledge
base*java.lang.NoClassDefFoundError: sun/misc/Unsafe
*
     at
org.mvel2.optimizers.dynamic.DynamicClassLoader.<clinit>(DynamicClassLoader.java:39)
[...]
     at
org.drools.rule.builder.dialect.java.AbstractJavaRuleBuilder.<clinit>(AbstractJavaRuleBuilder.java:27)
     at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
[...]
Caused by: *java.lang.ClassNotFoundException*: *sun.misc.Unsafe* not found
by GOSGi [1]


ARGH! Should be a problem due to the modified class loader?
Because sun.misc.unsafe is part of rt.jar that should be java standard..

That is improper thinking when using OSGi. The only thing that bundles get access to for "free" are classes in java.* packages. Anything else must be imported, whether it is part of rt.jar or not. Conversely, someone else must export it if someone else is importing it. Typically for packages that are part of the JRE, the system bundle exports them, but this wouldn't be true for sun.misc because it is a non-standard JRE package. If you want to have the system bundle export that, you'll need to edit the org.osgi.framework.system.packages.extra property to include it.

-> richard


Suggestion?!

THANKSSS!!!!!


--Antonello




2011/9/26 Rob Walker<[email protected]>

Antonello

Importing a package does not imply sub-packages, so it could be as simple
as adding an import for:

org.apache.activemq.jndi

Another area you often trip over with factory classloaders in libraries is
use of getContextClassloader() calls low down in the call stack.

Standard workaround for this is in relevant sections of your code where
threads get created/initialise to process requests is to set the context
classloader e.g.

        Thread.currentThread().**setContextClassLoader( this.getClass().**
getClassLoader());

OSGi is great, but you do stumble on a few class loading issues when
getting started - hang in there.

Regards

-- Rob Walker

On 26/09/2011 1:28 PM, Antonello Calabrň wrote:

Hi all,
I am a newbie in OSGi development, so I hope this will be Yet Another Dumb
Question :)
I am trying to convert a java application to an OSGi Bundle using Eclipse
and running it on apache felix-framework 3.2.2

I translated the main class that contains information about the startup in
an Activator class using the OSGi pattern.

Everything goes fine during compilation, but at runtime, the bundle
crashes
when it tries to create an

*initConn = new InitialContext(**environmentParameters);*

*Stack report:*
javax.naming.**NoInitialContextException: Cannot instantiate class:
org.apache.activemq.jndi.**ActiveMQInitialContextFactory [Root exception
is
java.lang.**ClassNotFoundException:
org.apache.activemq.jndi.**ActiveMQInitialContextFactory]
[...]    at
javax.naming.spi.**NamingManager.**getInitialContext(**
NamingManager.java:674)
Caused by: java.lang.**ClassNotFoundException:
org.apache.activemq.jndi.**ActiveMQInitialContextFactory
     ... 11 more

The *environmentParameters* are:

java.naming.factory.initial =
org.apache.activemq.jndi.**ActiveMQInitialContextFactory
java.naming.provider.url = tcp://myServer:61616
java.naming.security.principal = system
java.naming.security.**credentials = manager
connectionFactoryNames = TopicCF
topic.serviceTopic = jms.serviceTopic

The appication, uses ActiveMQ as JMS messageBroker.
I read something about "two version of JMS in my classpath", but I tried
to
remove the javax.jms without valid results

*Here, the application manifest*

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: GOSGi
Bundle-SymbolicName: GOSGi
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.myApp.osgi.Activator
Bundle-**RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: javax.jms,
  javax.naming,
  org.apache.activemq,
  org.osgi.framework;version="1.**3.0"
Bundle-ClassPath: .,
  externallib/activemq-all-5.3.**2.jar,
  externallib/drools-api-5.1.1.**jar,
  externallib/drools-core-5.1.1.**jar,
  externallib/javax.jms.jar,
  externallib/jsr173_1.0_api.**jar,
  externallib/resolver.jar,
  externallib/saxon9he.jar,
  externallib/xbean_xpath.jar,
  externallib/xbean.jar,
  externallib/xmlbeans-qname.**jar,
  externallib/xmlpublic.jar,
  lib/ComplexEventResponse.jar,
  lib/ComplexEventRule.jar
Export-Package: javax.jms,
  org.apache.activemq
Bundle-ActivationPolicy: lazy


*Here the build.properties*


source.. = src/
output.. = bin/
bin.includes = META-INF/,\
                .,\
                Conf/,\
                externallib/activemq-all-5.3.**2.jar,\
                externallib/drools-core-5.1.1.**jar,\
                externallib/javax.jms.jar
jars.extra.classpath = externallib/activemq-all-5.3.**2.jar,\
                        externallib/drools-api-5.1.1.**jar,\
                        externallib/drools-core-5.1.1.**jar,\
                        externallib/javax.jms.jar,\
                        externallib/jsr173_1.0_api.**jar,\
                        externallib/resolver.jar,\
                        externallib/saxon9he.jar,\
                        externallib/xbean_xpath.jar,\
                        externallib/xbean.jar,\
                        externallib/xmlbeans-qname.**jar,\
                        externallib/xmlpublic.jar

The code, as Java application, works fine...

May anyone help me? :)

Thank you!


--


Ascert - Taking systems to the Edge
[email protected]
+44 (0)20 7488 3470
www.ascert.com


------------------------------**------------------------------**---------
To unsubscribe, e-mail: 
users-unsubscribe@felix.**apache.org<[email protected]>
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to