Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Classes not being found(Standard Java classes not being found)
Classes not being found [message #1731237] Tue, 03 May 2016 16:38 Go to next message
Bill Mair is currently offline Bill MairFriend
Messages: 72
Registered: July 2009
Member
When deploying a bundle I'm getting a NoClassDefFoundError for "javax.naming.NameNotFoundException".

javax.naming has been part of the platform since Java 1.3 I think, so what is going on?

I tried adding import package "javax.naming", then "javax.naming.directory" but then Virgo complains with a ClassNotFoundException for "org.apache.naming.java.javaURLContextFactory". I don't refer to this package anywhere in my bundle (a "javax.naming.NoInitialContext" was in the stack) so it has to be an implementation/configuration issue somewhere.

I don't want to have to declare "all" the core API packages like "javax.naming" and "javax.naming.directory" as package imports, nor do I want think about what classes the platform "might" use to implement the functionality (e.g. org.apache.**).

What do I need to add to the Virgo server configuration to get my bundles to work?

Indeed, if this can be configured, shouldn't this be part of the standard configuration?
Re: Classes not being found [message #1731292 is a reply to message #1731237] Wed, 04 May 2016 07:32 Go to previous messageGo to next message
GianMaria Romanato is currently offline GianMaria RomanatoFriend
Messages: 49
Registered: November 2015
Member
Hi Bill,

In a OSGi container the system bundle exports automatically java.* packages for the benefit of other bundles and as such you are not required to import java.* packages..

The javax.* packages however are not automatically available and you are usually required to import them. This is not immediately visible when developing with PDE, because several javax.* packages are part of the JVM rt.jar which is included per default in every Java project class path and as such PDE is not currently able to give you a compile error if you forget to import the javax.* packages from the rt.jar [1]. However, if you forget the import you will experience a runtime error as in your case.

So in short, you should import the javax.* packages you are using. It's probably possible to circumvent this requirement by tweaking the OSGi framework boot delegation [2] but that is not recommended.

I noticed that the classes that are failing to load are from the JNDI packages. Please note that in OSGi you should comply with the OSGi way of using JNDI [3] as opposed to the JavaSE / JavaEE approach. As an alternative, you may find interesting an old blog post of mine discussing how to add "traditional" OSGi support to Virgo [4]

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=164188
[2] https://wiki.eclipse.org/Equinox_Boot_Delegation
[3] http://www.eclipse.org/gemini/naming/
[4] http://devshards.blogspot.it/2012/10/global-jndi-support-in-virgo-server-35.html

Hope this helps.
GianMaria.
Re: Classes not being found [message #1731320 is a reply to message #1731292] Wed, 04 May 2016 09:24 Go to previous messageGo to next message
Bill Mair is currently offline Bill MairFriend
Messages: 72
Registered: July 2009
Member
Hi GianMaria,

I've looked at the alternative solutions you referred to.

The tooling for PDE and OSGi has indeed been leading me a stray.

It is not apparent that javax.* has to be explicitly imported and I never saw this behaviour when running an "equinox" server.

Is there a plugin available that can alert me to the missing imports?

Also, the DNS issue was me "just" creating an InitialDirContext without explicitly requesting a DNS factory instance.

I am now undecided as to whether I should use the "osgi.compatibility.bootdelegation" option or not. I would love it if the PDE or maybe even the Virgo tooling could flag up missing imports.

-

Bill

[Updated on: Wed, 04 May 2016 10:31]

Report message to a moderator

Re: Classes not being found [message #1733283 is a reply to message #1731320] Thu, 26 May 2016 00:41 Go to previous message
GianMaria Romanato is currently offline GianMaria RomanatoFriend
Messages: 49
Registered: November 2015
Member
Sorrt for the late reply, I did not notice this message.

Bill Mair wrote on Wed, 04 May 2016 11:24
Hi GianMaria,
It is not apparent that javax.* has to be explicitly imported and I never saw this behaviour when running an "equinox" server.

Is there a plugin available that can alert me to the missing imports?


That's probably because of a different boot delegation policy. Eclipse itself, configures Equinox to make automatically available a large number of packages that you would otherwise need to import explicitly. I guess this is because in Eclipse RCP it's more common to use Require-Bundle than Import-Package so Equinox is configured to reduce the learning curve of plug-in developers.

I am not aware of any plug-in that can help you. However, if you compile with Maven/Tycho for example, I think Tycho will refuse to compile your code if a javax.* package is not imported. So if you use some sort of continuous integration you may be alerted soon. In any case, this is really something to which I am sure you will get used very soon.

Quote:

I am now undecided as to whether I should use the "osgi.compatibility.bootdelegation" option or not. I would love it if the PDE or maybe even the Virgo tooling could flag up missing imports.


I am not aware of a way PDE can be extended to overcome this limitation. I believe it's a non trivial issue otherwise the PDE team would have already solved it.

The Virgo tools just integrate Virgo in Eclipse and I cannot really work around the PDE limitations.

Personally I would avoid to tweak with bootdelegation, unless you are 100% sure you will never want to try another Application Server, because not all OSGi application servers allow to configure all aspects of the OSGi runtime.
For example, IBM WebSphere Liberty does not allow to control bundle start level and activation order.

GianMaria
Previous Topic:OSGI fragment bundle not connected to websockets deployed in Virgo nano
Next Topic:How to modify a web app context path at runtime?
Goto Forum:
  


Current Time: Fri Nov 16 07:20:08 GMT 2018

Powered by FUDForum. Page generated in 0.01868 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top