Hello, I know this question is stupid, but I cannot find an exact answer to it.
I am using Eclipse, and have written some classes to be used as a small database editor for XML. It compiles and runs fine in Eclipse.
However, I made it so that it can be used by people who are not programmers, and therefore probably don't have Eclipse. So I thought it'd be easier just to run 'java TEditor' (as it is named) in command prompt.
When I try to run the program using java.exe, though, it says 'Exception in thread "main" java.lang.NoClassDefFoundError: TEditor'.

A couple more things:
1) I am absolutely sure my class has a main method.
2) My classes have already been compiled, unless Windows is lying to me and TEditor.class is not really there, or if I am just delusional and think its there.
3) I tried manually compiling another, smaller class with javac.exe. Then I tried running it with java.exe, and got the same error.

It may be a problem with my CLASSPATH and PATH settings. I tried setting my CLASSPATH to the location of my lib\tools.jar location, as someone else had written, and my PATH includes bin\ in my Java directory.
It has been (obviously) a long time since I have used javac.exe to compile and java.exe to run a program, but I don't think that my CLASSPATH variable is correct.
Sorry for my dumb question :(

Recommended Answers

All 8 Replies

You are most likely correct that you're having a classpath issue.

My guess is you're on a windows machine.

Create a file called database.bat (the real name doesn't matter, but the .bat part does)>

then add the following code into your bat file...

# cp stand for cp here...
set cp = <one of your required jar files>
set cp = %cp%;<another one of your required jar files>
set cp = %cp%;<directory to your compiled code. you usually only have to state the base directory and all the class files will be brought in.>

java -cp %cp% TEditor

Then you should be good. Of course you're going to have to play with it a little bit, but the above bat file should work for you.

Hmm.... I don't need any jar files for this program, so I just used:

set cp = "<location here>"
java -cp %cp% TEditor

but I got the same error as before.

did you actually type <location here>? Or did you use something like C:/code/src?

Yes, I actually typed <location here>. No, just kidding; I am not quite that dumb. Its just that the folder was in my documents, which has some personal information in the name.


I would recommend trying to jar up your application and then pointing your classpath toward your jar file. I'm not exactly sure how to get individual classes into the classpath. I think you just point to their base directory. But i'm not positive.

Are you using packages? That could be part of the issue if you're not.

To jar up your application. in a command prompt window go to your applications directory and type: jar -cvf <your jar name>.jar /<the first folder of your package name> and your should get a new jar file in your directory named <your jar name>.jar. Then place this jar file in your classpath.

I made my classes into a jar file. The folder it now is in is C:\jarme\
and the jar filename is
I tried something to the effect of:
set cp=C:\jarme\myjar.jar;C:\jarme\
java -cp %cp% myjar.jar
Which did not work, nor did I really expect to, so I tried
java -cp %cp% TEditor
Which did not work either, but gave a longer error message about the native methods. So I tried
java -jar C:\jarme\myjar.jar
And that gives the error "Failed to load Main-Class manifest attribute from\nC:\jarme\myjar.jar" (except the \n is a new line)

Are you using packages in your java classes? If you're using packages you need to go <your>.<package>.<extension>.<here>.TEditor

Here is an example without packages that works.

I created a java file called Test.java in my C:/java/src/examples/examples directory...

// Notice no package info...
public class Test 
	public static void main(String[] args)

I then opened a command prompt window and navigated to the C:/java/src/examples/examples directory and ran the following command:

javac -verbose -cp . Test.java

I recieved the following output:

[parsing started Test.java]
[parsing completed 31ms]
[search path for source files: [.]]
[search path for class files: [C:\jdk1.5\jre\lib\rt.jar, C:\jdk1.5\jre\lib\jsse.jar, Z:\jdk1.5\jre\lib\jce.jar, C:\jdk1.5\jre\lib\charsets.jar, C:\jdk1.5\jre\lib\ext\dnsns.jar, C:\jdk1.5\jre\lib\ext\localedata.jar, C:\jdk1.5\jre\lib\ext\sunjce_provider.jar, C:\jdk1.5\jre\lib\ext\sunpkcs11.jar, .]]
[loading C:\jdk1.5\jre\lib\rt.jar(java/lang/Object.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/lang/String.class)]
[checking Test]
[loading C:\jdk1.5\jre\lib\rt.jar(java/lang/System.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/io/PrintStream.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/io/FilterOutputStream.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/io/OutputStream.class)]
[wrote Test.class]
[total 313ms]

I then created a new .bat file in C:/java/src/examples called test.bat...

set cp=C:\java\src\examples\examples

java -cp %cp% Test

Finally in my command prompt window i navigated to C:/java/src/examples and then ran the following command:


I recieved the following output:


I also just tried this example with creating a jar file... And it still works. (Luckly for me.)

So, to use a jar file...

Create the jar file by being in the C:/java/src/examples/examples directory in a command prompt window and run the following command:

jar -cfv test.jar Test.class

I recieved the following output:

added manifest
adding: Test.class(in = 406) (out= 277)(deflated 31%)

Then i changed the test.bat file to:

set cp=C:\java\src\examples\examples\test.jar

java -cp %cp% Test

I then re-ran the test.bat file and recieved the following output:


Thanks, the package thing did finally get it to work. Well, at first it didn't until I put the files into a folder with the same name as the package.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.