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?

John John Pichler
  • 4,427
  • 8
  • 43
  • 72

4 Answers4

6

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

Import-Package: javax.swing
Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • @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.bundle – Suraj Chandran Mar 03 '11 at 17:09
  • 3
    @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.*". – Neil Bartlett Mar 04 '11 at 05:04
  • @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. – Suraj Chandran Mar 04 '11 at 05:17
  • @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. – Neil Bartlett Mar 04 '11 at 05:17
  • 3
    @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. – Neil Bartlett Mar 04 '11 at 05:20
  • @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 answer – Suraj Chandran Mar 04 '11 at 05:44
  • @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. – Neil Bartlett Mar 04 '11 at 05:49
  • @Neil ohh...my bad, i automatically assumed that he would look in to the bootdelegation part of the profile – Suraj Chandran Mar 04 '11 at 06:05
  • 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? – John John Pichler Mar 04 '11 at 12:14
  • ohhhh... now it works! I configured boot delegation in config file! – John John Pichler Mar 04 '11 at 12:17
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

Steve
  • 8,066
  • 11
  • 70
  • 112
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?

John John Pichler
  • 4,427
  • 8
  • 43
  • 72
0

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

Suraj Chandran
  • 24,433
  • 12
  • 63
  • 94
  • No... But as I said, the MainFrame is located in the same bundle the activator is – John John Pichler Mar 03 '11 at 13:39
  • you have to mention the Bundle-ClassPath. though by default it may pick up "." but just o be sure... – Suraj Chandran Mar 03 '11 at 13:52
  • 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. – John John Pichler Mar 03 '11 at 14:07
  • he he...i had asked this question in SO sometime back : http://stackoverflow.com/questions/1458425/who-loads-javax-swing-classes-in-equinox-osgi-container – Suraj Chandran Mar 03 '11 at 14:08
  • Suraj, you seem to be guessing at the answer. If you don't know, it's better not to answer at all. – Neil Bartlett Mar 03 '11 at 15:54
  • I've already putted on MANIFEST-MF file the property "Bundle-RequiredExecutionEnvironment: J2SE-1.5" but no sucess =[ – John John Pichler Mar 03 '11 at 17:03
  • @Neil I am only helping. And I am so damn sure that every point I have mentioned is a very possible solution for his problem – Suraj Chandran Mar 03 '11 at 17:17
  • @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. – Suraj Chandran Mar 03 '11 at 17:22
  • Suraj, there is no javax.swing there... How could I use the profile? In profile file I found the javax.swing declared... – John John Pichler Mar 03 '11 at 17:41
  • @EdPichler you mean "javax.swing" is declared inside your J2SE-1.5.profile file or not? – Suraj Chandran Mar 03 '11 at 17:43
  • Yes, it is declared there. How can I use it? – John John Pichler Mar 03 '11 at 18:00
  • setting Bundle-RequiredExecutionEnvironment to J2SE-1.5 should automatically use that file – Suraj Chandran Mar 03 '11 at 18:11
  • 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? – John John Pichler Mar 03 '11 at 20:51
  • 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. – Neil Bartlett Mar 04 '11 at 05:06
  • @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. – Suraj Chandran Mar 04 '11 at 05:15
  • @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. – Neil Bartlett Mar 04 '11 at 05:27
  • 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. – John John Pichler Mar 04 '11 at 11:44