3

I have created a simple Java program (1 java file that contains the main() ), and I've included all Jar files in the same directory as the .class file. It is giving the NoClassDefFoundError message.

I've tried updating the Classpath to point to the directory, and I've also set "-cp ." to suggest that it look in the same directory as the .class file. However, the program still says it can't find the class def.

Any thoughts on what I should do?

32Street
  • 51
  • 1
  • 6
  • Which class, which jars, which code? Wat? – Maxim Kolesnikov Apr 02 '13 at 20:03
  • sorry for any confusion. My program is one java class that contains the main(). My program needs to reference several packages (*.jar). I hope this helps. – 32Street Apr 02 '13 at 20:09
  • Problem solved: I had updated the classpath in the Windows OS, but I needed to run the Java program in a new Command window... so the new classpath would be active. thank you for your help! – 32Street Apr 02 '13 at 20:12

3 Answers3

0

Adding a folder tells java to look in that folder for .class files. You can't reference .jar files via a folder name... Each .jar file's path must be listed on the CLASS_PATH explicitly.

this question's answer may be useful

Community
  • 1
  • 1
Chris Nava
  • 6,614
  • 3
  • 25
  • 31
0

When you try running a class from command line then a NoClassDefFound exception usualy means there is something wrong with your classpath.

You have explicitly define the classpath. You can do this in a few ways but the following way is the least prone to error:

Open a command shell and do the following:

1.) set classpath = {path to class files};{path to jars}

2.) java com.example.mainclass

Note: Even if your classes path and jar path is the same you need to specify them explicitly.

Note: If you have more then one jars place them in a folder say lib and add it to the classpath like: {path}/lib/* This will include all of the jar otherwise you have to specify them individually.

References: https://javarevisited.blogspot.com/2011/01/how-classpath-work-in-java.html

Malkeith Singh
  • 235
  • 1
  • 8
-6

Import the following package:

Import java.lang.NoClassDefFoundError;
Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182