Mike Hofer
Mike Hofer

Reputation: 17022

Bizarre "NoClassDefFound" Error

This one really has me stumped.

Scenario:

The problem:

  1. If I do not explicitly include the two aforementioned JAR files in my build path, the application fails to compile (trying to import org.eclipse.swt.widgets.Display and com.ibm.rcp.swt.swidgets.SToolItem).
  2. If I include the aforementioned JAR files in the build path, the application compiles, but won't run, due to a NoClassDefFound exception.

The questions:

  1. Why do I need to include these files in the first place? They are part of the workspace, and none of the other JAR files I'm referencing seem to need to be explicitly referenced.
  2. Why is this failing at run time? My understanding is that NoClassDefFound occurs because the class was available at compile time, but isn't at run time. But this is occurring on the same machine. (I'm trying to debug it locally, and I've even marked the JAR files for export!)

It seems to me that if the files are listed in the Runtime Configuration's loaded plugins tab, I wouldn't have to explicitly reference them. Am I incorrect regarding this? (Please be kind! I'm admittedly not an expert at this.)

Thanks in advance.

P.S. It's worth noting that if I include the files in the build path, I can see that they are properly referenced in both MANIFEST.MF and the .CLASSPATH file.

MANIFEST.MF CONTENTS

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin
Bundle-SymbolicName: com.satuit.crm.plugin;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.satuit.crm.plugin.Activator
Bundle-Vendor: Satuit Technologies, Inc.
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.apache.axis,
 org.eclipse.ui;bundle-version="3.4.2",
 org.eclipse.core.runtime;bundle-version="3.4.0",
 org.eclipse.ui.views;bundle-version="3.3.1",
 com.ibm.rcp.jfaceex;bundle-version="6.2.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: com.satuit.crm.plugin,
 com.satuit.crm.plugin.document,
 com.satuit.crm.plugin.ui,
 com.satuit.crm.webservice.agent
Bundle-ClassPath: .,
 /NotesDev/Notes/framework/rcp/eclipse/plugins/org.eclipse.swt.win32.win32.x86_3.5.2.v3557f-RCP20100710-0200.jar,
 /NotesDev/Notes/framework/rcp/eclipse/plugins/com.ibm.rcp.swtex.win32_6.2.2.20100729-1241.jar,
 /NotesDev/lib/activation-1.1.1.jar,
 /NotesDev/lib/mail.jar,
 /NotesDev/lib/commons-lang3-3.1.jar,
 /NotesDev/lib/SatuitCRM_XML_API2.jar

** .CLASSPATH CONTENTS **

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry exported="true" kind="con" path="org.eclipse.pde.core.requiredPlugins"/>  
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.eclipse.swt.win32.win32.x86_3.5.2.v3557f-RCP20100710-0200.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/com.ibm.rcp.swtex.win32_6.2.2.20100729-1241.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Workspace/lib/commons-lang3-3.1.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Workspace/lib/activation-1.1.1.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Workspace/lib/mail.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Workspace/lib/SatuitCRM_XML_API2.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/axispatch.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/axis.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/jaxrpc.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/saaj.jar"/>
    <classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/wsdl4j-1.5.1.jar"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Upvotes: 0

Views: 628

Answers (3)

Mike Hofer
Mike Hofer

Reputation: 17022

Well, as it turns out, the OSGI manifest will accept absolute paths on the classpath. Surprise, surprise.

Whether or not it should is another story. And what that will do to the application once it's deployed is anyone's guess. But the runtime and compile time errors have disappeared, and so far don't appear to be resurfacing.

Once again, what we considered fact and actual fact turned out to be two very different things.

Upvotes: 0

Paul Webster
Paul Webster

Reputation: 10654

The OSGi MANIFEST won't accept absolute paths to jars on the system (it's for including jars within the bundle), and if you update the Java Build Path it probably won't work when it's deployed.

Fundamentally, you're writing an OSGi bundle and you have to be careful with the classpath. It looks like there are 2 different issues you have to change.

  1. org.eclipse.swt.win32.win32.x86_3.5.2.v3557f-RCP20100710-0200.jar and com.ibm.rcp.swtex.win32_6.2.2.20100729-1241.jar are already OSGi bundles. They need to be in your target platform. Then, you need to add them to Required-Bundles, just like com.ibm.rcp.jfaceex. To be honest, they look like fragments. In that case, org.eclipse.swt.win32.win32.x86 should be picked up automatically because you consume org.eclipse.ui, which re-exports org.eclipse.swt. It might be that you need to add a Require-Bundle on com.ibm.rcp.swtex (a possible host bundle for the win32 swtex fragment)

  2. All of those jars you've added to the Bundle-ClassPath. Are the classes you need not in packages already in your target platform? Ideally you want to consume them from existing OSGi bundles. At least org.apache.axis is already an OSGi bundle. For the rest of them, if you really need classes from those jars and they don't already exist as exported packages in your target platform, you need to either turn them into OSGi bundles and include them in your target platform or actually include them in your eclipse project, and add them to your Bundle-ClassPath from there (it'll be a project root relative path).

Upvotes: 1

Chris Gerken
Chris Gerken

Reputation: 16392

You can also get the NoClassDefFound error when a class referenced by Display or SToolItem isn't found. The only way I know to figure out exactly which class can't be found is to run the java app with the -verbose option. You get far more logging than you ever want to see, but somewhere in all those lines of output is an error message naming the specific class that can't be found.

Upvotes: 1

Related Questions