java.lang.NoClassDefFoundError on OSGi
Asked Answered
N

4

6

I have a bundle, with an activator declared. This activator create a JFrame and show it.

Running on Eclipse as Plugin project it works fine. When I put on Felix it doesn't work anymore. It shows: java.lang.NoClassDefFoundError: com/griep/ui/MainFrame

But MainFrame is located in the same bundle the activator is, as a public class, of course. I don't understand why the classloader isn't finding the class.

Anyone knows what is happening?

Neoterize answered 3/3, 2011 at 13:18 Comment(1)
is there a wrapped exception?Kooima
K
6

Make sure you import the javax.swing package into your bundle:

Import-Package: javax.swing
Kenric answered 3/3, 2011 at 15:52 Comment(10)
@Neil no this is wrong, the OPhas is osgi profile set to Bundle-RequiredExecutionEnvironment: J2SE-1.5, which means that javax.* packages should automatically be exported by system.bundleKooima
@Suraj Sorry to have to disagree publicly, but just because the javax.swing package is exported by the system bundle does not mean it is imported automatically by every other bundle. The rule in OSGi is that you must import that packages that you use, with the sole exception of "java.*".Kenric
@Neil @Neil Have you even tried it out before writing such a thing. I can use javax.swing package without importing it. Do you know the concept of "Bundle-RequiredExecutionEnvironment" and the concept of profiles. Atleast write some code and check yourself before misleading others.Kooima
@Ed I have checked the bundles you uploaded to Google docs verified that you are missing the following imports from your OSGi_Carteiras_Manager bundle: javax.swing, javax.swing.border, javax.swing.event, org.aspectj.internal.lang.annotation, org.aspectj.lang.annotation, org.jfree.chart, org.jfree.chart.labels, org.jfree.chart.plot, org.jfree.data, org.jfree.data.general, org.jfree.data.time, org.jfree.data.xy.Kenric
@Suraj Yes I have tried it and yes I do know about BREE and profiles. Have you read my book or my blog posts about OSGi? ;-) The reason that you can use javax.swing on SOME environments without importing it is because of a nasty hack used by Eclipse org.osgi.framework.bootdelegation=*. This hack should never be relied upon, as it leads to exactly the errors encountered by Ed. The proper way to use a package in OSGi is to import it.Kenric
@Neil "hack used by Eclipse org.osgi.framework.bootdelegation=*" exactly, thats why I asked him to check that in the profile and the OP has accepted that it was there, see his comments in my answerKooima
@Suraj That's not what you asked OP to do at all, you asked him about javax.swing being listed in the profile. Of course it's listed in the profile, but that's not the problem! There is nothing wrong with the configuration of the OSGi Framework, it's just a missing import (actually, lots of missing imports) in the OP's own bundles. He needs to fix the bundles, not the framework. Please, just cool off now and wait for OP to respond.Kenric
@Neil ohh...my bad, i automatically assumed that he would look in to the bootdelegation part of the profileKooima
So, I need to configure "boot delegation"? I don't want to declare import of all these packages. Why it works in Eclipse IDE PDE environment?Neoterize
ohhhh... now it works! I configured boot delegation in config file!Neoterize
S
2

Use this VM argument:

-Djava.specification.version=1.6

This will force Felix to make available the default set of system packages for Java 6, which includes javax.swing and its sub-packages

Sodalite answered 16/2, 2013 at 13:53 Comment(1)
I used that time, but weren't enough. ThanksNeoterize
N
1

Now it works! I configured boot delegation in config file!

I put org.osgi.framework.bootdelegation= in config.ini.

Both of you should told me this before guys hehe. Now I read in equinox wiki, that following the OSGi specification I need to define every package I need to use, and I think its right, because some customized VMs can have more libs than other.

But Eclipse don't works in this concept of importing every java package (like javax.swing). I'll report this in Eclipse Bugzilla.

Many thanks both you!

PS: What are your book @Neil?

Neoterize answered 4/3, 2011 at 12:24 Comment(0)
K
0

Have you declared the Bundle-ClassPath in your bundle's MANIFEST.MF

Kooima answered 3/3, 2011 at 13:24 Comment(17)
No... But as I said, the MainFrame is located in the same bundle the activator isNeoterize
you have to mention the Bundle-ClassPath. though by default it may pick up "." but just o be sure...Kooima
hmmmm I found a nested excpetion in logs... Caused by: java.lang.ClassNotFoundException: javax.swing.JFrame Why do I need to declare? JFrame is in java default library.Neoterize
he he...i had asked this question in SO sometime back : #1458925Kooima
Suraj, you seem to be guessing at the answer. If you don't know, it's better not to answer at all.Kenric
I've already putted on MANIFEST-MF file the property "Bundle-RequiredExecutionEnvironment: J2SE-1.5" but no sucess =[Neoterize
@Neil I am only helping. And I am so damn sure that every point I have mentioned is a very possible solution for his problemKooima
@Ed Open your org.eclipse.osgi.* jar and there must be a file inside named J2SE-1.5.profile. Make sure that"javax.swing" is mentioned in that file. If not try using other profiles or just add it.Kooima
Suraj, there is no javax.swing there... How could I use the profile? In profile file I found the javax.swing declared...Neoterize
@EdPichler you mean "javax.swing" is declared inside your J2SE-1.5.profile file or not?Kooima
Yes, it is declared there. How can I use it?Neoterize
setting Bundle-RequiredExecutionEnvironment to J2SE-1.5 should automatically use that fileKooima
I don't know what's happening here... I already did this before with Felix implementation without problems. I'll upload this file to you run in your machine if you want... it's a graph application to generate investment charts. Do you just want try to run it?Neoterize
This is the wrong solution. Just because the system bundle exports javax.swing does not mean it is automatically imported by every other bundle. The rule in OSGi is that you must explicitly import every package you use, with the sole exception of "java.*" (e.g. java.lang, java.util etc). @Ed please try my solution and report what happens.Kenric
@Neil Have you even tried it out before writing such a thing. I can use javax.swing package without importing it. Do you know the concept of "Bundle-RequiredExecutionEnvironment" and the concept of profiles. Atleast write some code and check yourself before misleading others.Kooima
@Suraj Please see my response in the other comment thread. I would suggest we cool off and wait for Ed to try my solution. If that works -- and I believe it will -- then I'm happy to explain in detail why your "solution" did not work.Kenric
I tried your solution Neil, because you are assertive. But it stops to show ClassNotFoundException of JFrame, and after of Border... now it's showing the same error but about JPanel.. very strange, because JPanel and JFrame are in the same package. So, it's not working yet.Neoterize

© 2022 - 2024 — McMap. All rights reserved.