Class in buildpath-jar still not found - java

I'm developing a eclipse plugin rcp and I'm running into a NoClassDefFoundError
Exception in thread "Thread-7" java.lang.NoClassDefFoundError: org/jdom/input/SAXBuilder
at org.geonames.WebService.search(WebService.java:783)
at geo.GeocoderGeonames$SearchThread.run(GeocoderGeonames.java:119)
Caused by: java.lang.ClassNotFoundException: org.jdom.input.SAXBuilder
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:483)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 2 more
The class that supposedly cannot be found is in a jar that I have added to the buildpath. I don't get any compile error etc only this exception when the running application enters the code where this class is needed...
Is there some other place I need to add the jar

After reading this added the jar to the MANIFEST.MF, which solved the problem.
As I understand it, eclipse starts several classloaders which only sees what MANIFEST.MF tells them to see and ingnores the build path...

How are you running your plug-in? You may need to add the JAR to the class path in the VM arguments.

In our experience a NoClassDefFoundError can sometimes mean that more than one version of a Class are found, as there is also a ClassNotFoundException that's normally thrown if a class cannot be found.
Another reason in your case (XML parser) might be something with endorsed classes. Are you directly importing the jdom classes or something like org.w3c...? If so, have a look at the "endorsed classes" system of Java, something that I just recently came across.

Related

JAssimp - Can't find dependent libraries

I've compiled the JAssimp library, and I'm trying to use the library in NetBeans with a project.
I'm setting the library path in Netbeans in the 'run' options of the project as such:
-Djava.library.path=D:\VB2013Projects\jassimpfinal\x64\Debug
That path is where jassimp.dll is located.
However, when I try to run my project, I get this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\VB2013Projects\jassimpfinal\x64\Debug\jassimp.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1929)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1847)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at jassimp.Jassimp.<clinit>(Unknown Source)
at opengltutorials.Mesh.loadMesh(Mesh.java:131)
at opengltutorials.Tutorial.init(Tutorial.java:124)
at opengltutorials.Tutorial.main(Tutorial.java:238)
I've checked the dependencies with Dependency Walker, and it shows that
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module. for jassimp.dll. However, it doesn't show any functions in red, so I think this is just a red herring (I am probably wrong, though).
What's going wrong with this?
Fixed this by putting the appropriate .dll's in the working directory.

Where do I get the missing resources?

I am still unable to get the box-api hello world program to work. I was getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/NotImplementedException
at TestProgram.getAuthenticatedClient(TestProgram.java:47)
at TestProgram.main(TestProgram.java:35)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.NotImplementedException
...
I then went to the Apache Commons Lang Home and downloaded and set up their thing.
Now I get
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at com.box.boxjavalibv2.jacksonparser.BoxResourceHub.<init>(BoxResourceHub.java:28)
at com.box.boxjavalibv2.BoxClient.createResourceHub(BoxClient.java:345)
at com.box.boxjavalibv2.BoxClient.<init>(BoxClient.java:65)
...
and I have no idea how to fulfill that dependency. I also suspect that even if I could find this one, there'd just be another one, and another one, and another one. Manually importing them all does not seem to be very realistic.
How am I intended to get the missing dependencies for the box API?
The SDK comes included with all of the dependencies you should need. You can find them all in the libs directory of the SDK..
Add all of those jars to your Eclipse build path and it should work.

ClassDefNotFoundError while class in classpath

I'm trying to run ParSeMiS. According to the documentation, it requires ant, prefuse and antlr jars to be available in its lib directory. I've put all the required jars in it. However, when I try to run it, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: antlr/TokenStreamException
at de.parsemis.miner.environment.Settings.parseFileName(Settings.java:198)
at de.parsemis.miner.environment.Settings.parseOption(Settings.java:312)
at de.parsemis.miner.environment.Settings.parse(Settings.java:170)
at de.parsemis.miner.environment.Settings.parse(Settings.java:122)
at de.parsemis.Miner.run(Miner.java:358)
at de.parsemis.Miner.main(Miner.java:61)
Caused by: java.lang.ClassNotFoundException: antlr.TokenStreamException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 6 more
Now, I've verified that antlr/TokenStreamException.class is present in the antlr jar. I have tried adding the jar manually to the classpath by both exporting the CLASSPATH variable and setting it via the -cp switch. However, none of that works, and I still get this exception. Can anybody help me figure out what's wrong? Thanks.
The problem is that you're using -jar which ignores your CLASSPATH environment variable. You should list your dependencies in the manifest, as shown here, e.g.
Class-Path: lib/ant.jar lib/antlr-3.4-complete.jar lib/prefuse.jar
(It should have still worked with an explicit -cp option, however. My guess is that you got something wrong when specifying that, and assumed it was the same underlying cause as the failure when using the environment variable.)
I realize this question is very old, but I just had exactly the same problem and found this thread. For posterity, I'm posting how I did eventually get it to run:
As mentioned above, when running with -jar, java apparently ignores the class path. So don't run it with -jar. instead include the jars in the path and run the class directly. Poking around, the following should work (paths are on my Ubuntu 12.10 system):
java -cp /usr/share/java/antlr.jar:/full/path/to/parsemis.jar de.parsemis.Miner
You can then pass in options to the above. Maye sure you use full paths, and no shortcuts like ~/foo, as they apparently don't expand.
Of course, if you're using a Dot-formatted graph like I am, it dies very early on complaining of "unexpected char 0xA", but at least it gets further.

getting javax.mail.MessagingException

I am using javax.mail .jar file to read the mail messages. But when i m running the code i am getting the following exception.
I added mail.jar in classpath.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingE
xception
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: MasterProcess. Program will exit.
any suggetionsn to solve this issue please ...
You're not getting a MessagingException, the VM is complaining that it can't find MessagingException (although it's probably that it's looking for it because it wants to throw it, but those are issues for later).
Check if your mail.jar actually contains this class, and check if your mail.jar really is on the classpath.
The last thing that could happen is that the class is incompatible with your version of Java. Classes compiled for 1.5 won't run on 1.4, for example.
Working in eclipse and not in command line clearly say that there is multiple versions of mail jar present in the project.
Ex:
You have 3 Jars , Jar X, Jar Y and Jar Z.
With out you knowing JAR X might be already be bundled inside JAR Z ( in this case mail jar but some different version.
So what is the problem in having multiple version of same jar ?
You have two different versions and you will not know which will be referenced in your project. (so if you are looking for some class from mail-2.jar in your project you will get class not found exception if the reference is made to mail-1.jar by class loader)
So how come its working properly on Eclipse ?
In eclipse you can see there is an option for ORDER the library, these will be reference in the same order, but while running in command prompt we used to load the as lib/* which loads all to gather and we will not know which lib will get loaded first.
How to identify the culprit and fix the issue ?
Option 1 :
See docs page / user guide of the libs you are using to see what they have in them.
Option 2 :
In eclipse move the JAR in question (mail.jar here) to TOP in the class path order. (your program should work now)
Now bring down the order one by one to see where you get the error. (if you wish to find the jar which is causing this issue , duplicate reference)
Extract the jar which has the duplicate reference remove the duplicate inside the JAR and repackage it. (if required)
Also be sure you're having also the java activation.jar jar.
Are you by any chance working with an App Server (eg. Jboss), if so, just check classloading model (in jboss with single classloading model you may be loading a not so up-to-date version of the jars)
I've also faced the same error. It happens to me that while compiling i used the jars correctly. While running it on command line i noticed the mail.jar (javamail API) was not included.

Odd NoClassDefFoundError

After installing the latest version of Vuze (Azureus), I got an odd error trying to start it:
> java -Xmx128m -classpath ./Azureus2.jar:./swt.jar -Djava.library.path=/bt_work/vuze -Dazureus.install.path=/bt_work/vuze -Dazureus.script=./azureus -Dazureus.script.version=2 org.gudy.azureus2.ui.swt.Main
Exception in thread "main" java.lang.NoClassDefFoundError: org/gudy/azureus2/ui/swt/Main
Caused by: java.lang.ClassNotFoundException: org.gudy.azureus2.ui.swt.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
What's odd is this:
> javap -classpath ./Azureus2.jar:./swt.jar org.gudy.azureus2.ui.swt.Main
Compiled from "Main.java"
public class org.gudy.azureus2.ui.swt.Main extends java.lang.Object{
public static final java.lang.String PR_MULTI_INSTANCE;
...
So ... running javap with the same classpath finds the class but java alone can't. WTF is going on?
I checked that both programs come from the same install Java (/usr/lib64/jvm/java-1.6.0-sun), that's Java 6 and the classes were compiled for Java 5. The manifest isn't signed. The JAR file is readable (unzip -t reports no errors).
NoClassDefFoundError happens when the class itself is found but the class loader cannot load all the classes it needs.
Can you check the import headers for class org.gudy.azureus2.ui.swt.Main.java and make sure that all the imported classes can be found in your classpath. If not, add the jar files to your classpath.
Post the import section if you want me to help figure out what is still needed.
One word: AppArmor
In my case, the config didn't allow the program java to load the JARs from the new installation path.
If you have a similar problem, look into /var/log/audit.log. You should see the error messages there.
Your exception is java.lang.NoClassDefFoundError and not exactly ClassNotFoundException - so javap will still be able to disassemble the class.
As you might know NoClassDefFoundError can be seen as a linkage error. I tend to guess that the runtime is missing some required class to execute org.gudy.azureus2.ui.swt.Main
I guess it requires more JARs on classpath.
So org.gudy.azureus2.ui.swt.Main is available (that is why javap works) but one of its dependency is not found during runtime.
Also running SWT sometimes requires -Djava.library.path set to swt library (looking at your SO reputation I guess you know this)
Edit
Here is a link to one Azureus shell script, which lists more classpath JARs.

Categories

Resources