ClassDefNotFoundError while class in classpath - java

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.

Related

How to use with Neo4j with Java simply using JDK Tools?

I'm trying to use neo4j embedded in a Java application for a small project of mine. For this, I'm only using JDK Tools, so, there's no Eclipse, Net Beans or IntelliJ IDEA.
I've tried to follow the tutorial supplied by Neo4j (Include Neo4j in your project) , but I'm somehow doing it wrong, since it doesn't work.
To sum up, I've got a small .java file, let's say it's only composed of the bare necessities to work and an import of org.neo4j
import org.neo4j; // or org.neo4j.*, or anything else that starts with that
public class Application
{
// only the bare necessities to work
}
I'm trying to compile this simple code with javac using -classpath to specify where to find Neo4j libraries, just like it's showed in the tutorial
javac -g -cp "C:/Path/to/libs/Neo4j Community/jre/lib" Application.java
But each time, the compilation fail at the line of the import, saying that the package doesn't exist. And of course, once this line is erased, the compilation succeed.
I've already tried to move the libs inside the project's folder, and I've tried to download the neo4j kernel jar and put it inside the Neo4j's folder and the project's folder, but, none of these solutions have worked.
If anyone could help me, I would be very thankful to him.
Cordially,
Jaxon
EDIT : When I try to compile with the following command :
javac -g -cp "C:\Path\to\libs\Neo4j Community\jre\lib\*" Application.java
The error stays and two warnings appear. I don't know if it's related, but here are the errors :
warning: Supported source version 'RELEASE_7' from annotation processor 'org.neo4j.kernel.impl.annotations.ServiceProcessor' less than -source '1.8'
warning: Supported source version 'RELEASE_7' from annotation processor 'org.neo4j.kernel.impl.annotations.DocumentationProcessor' less than -source '1.8'
Application.java:4: error: package org.neo4j does not exist
import org.neo4j.*;
^
1 error
2 warnings
EDIT : I now have a program that compiles, but when I run it, there is an exception that crash the program. The code haven't changed a lot, the only difference is that now I import org.neo4j.graphdb.* and org.neo4j.graphdb.factory.*
Here is the exception returned :
Exception in thread "main" java.lang.NoClassDefFoundError: org/neo4j/graphdb/factory/GraphDatabaseFactory
at MyApp.connection(MyApp.java:18)
at MyApp.<init>(MyApp.java:13)
at MyApp.main(MyApp.java:8)
Caused by: java.lang.ClassNotFoundException: org.neo4j.graphdb.factory.GraphDatabaseFactory
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)
... 3 more
Well I understand what the exception means but I don't know how to solve the problem. Probably because according to the Neo4j documentation, GraphDatabaseFactory is in org.neo4j.graphdb.factory. So I don't know where to go...
You need to use a * wildcard to specify all the jar files in the lib folder. Try this:
javac -g -cp "C:/Path/to/libs/Neo4j Community/jre/lib/*" Application.java
[EDIT]
Of course, you must use your computer's actual path to the lib directory. "C:/Path/to/libs/Neo4j Community/jre/lib/*" is just an example.
Also, warnings like the following (which mean that some parts of the library were annotated to indicate that they support Java 1.7, but you are compiling with Java 1.8) may not prevent the resulting .class files from running properly:
warning: Supported source version 'RELEASE_7' from annotation processor 'org.neo4j.kernel.impl.annotations.ServiceProcessor' less than -source '1.8'
However, if you want to be sure, one way to get rid of this warning is to downgrade your JDK to 1.7.

Oracle Weblogic adding jars to the classpath?

How do you add jars to the class path for Oracle 10.3.5...As I understood it, there is a bug (or incorrect info) with the documentation (readme) that states that any jars placed in the $DOMAIN_HOME/lib directory would be added to the classpath dynamically...but in the real documentation for 10.3.3 it states that these files dont get added to the classpath anymore...
so here I am trying to find out -- how do you add jars to the classpath...I have tried changing the commonEnv.sh and am currently looking for the setDomainEnv.sh (but cant find it as of yet) and none of these things have worked to add this jar to the classpath...
my whole problem is that i added datasources to my server...and I am trying to add the DB2 jar to the environment so that it can be used...funny thing is that after adding the jar in the $DOMAIN_HOME/lib I was able to get rid of a connection error in the admin console when trying to test the connection to the database...and that all seems to work but now im getting a class definition error...
]] Root cause of ServletException.
java.lang.NoClassDefFoundError: com/ibm/db2/jcc/DB2Connection
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:630)
at java.lang.ClassLoader.defineClass(ClassLoader.java:614)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at weblogic.utils.classloaders.GenericClassLoader.defineClass(GenericClassLoader.java:343)
Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Connection
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
at java.lang.ClassLoader.loadClass(ClassLoader.java:305)
at java.lang.ClassLoader.loadClass(ClassLoader.java:246)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)
Truncated. see log file for complete stacktrace
idk what else to try - i searched for some answers but seemingly all of them are old and outdated...
$DOMAIN/lib should work fine, but not dynamically. You have to restart. However, handling JAR files for data source drivers is likely different.
Just curious - have you confirmed the jar file(s) contain he class in question?
Also try: http://docs.oracle.com/cd/E17904_01/web.1111/e13753/db2.htm
I ended up finding out the problem was that I was editing the commEnv.sh file on windows instead of the commEnv.cmd file...really dumb but editing that and adding the jar to the classpath there worked...bah!

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.

Class in buildpath-jar still not found

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.

Categories

Resources