Hi there folks,

Very new to java and I have what I hope will be a simple question...

I have JDK 1.5 installed on my C: drive and my source on my E: drive (flash drive). I'm trying to run the source and I always get NoClassDefFound errors when I try to run the program. Compile seems to work (no errors). Here is what I have tried...

C:\Sun\SDK\jdk\bin\java E:\Chap1\source.java

C:\Sun\SDK\jdk\bin\java "E:\Chap1\source.java"

I've fooled around with this quite a bit but no joy. I checked out the parameter options for java and javac but didn't see anything that would clearly address this. I want to compile such that the class file is created in the same directory as the source file.

Its worth noting that when I copy the source file to the directory where the compiler and java are located (C:\Sun\SDK\jdk\bin\) and try it there everything works fine.

Anyone have any suggestions?

Many Thanks!

Tyster

That error normally occurs when you try to run the java class file without having first compiled it. The correct (two) commands are:

javac E:\Chap1\source.java
java E:\Chap1\source

As far as I know it shouldn't matter where your files are located if you provide the full path.

Oddly, if I run...

C:\Sun\SDK\jdk\bin\javac E:\Chap1\source.java

It works. I get 'source.class' in E:\Chap1. But when I try to tun the program with...

C:\Sun\SDK\jdk\bin\java E:\Chap1\source

I get this error...

Exception in thread "main" java.lang.NoClassDefFoundError: E:\Chap1
\source

I tried fooling with the -d parameter but no luck.

Anyone have any ideas?

Many Thanks!

...Tyster

Use the -cp parameter to put that directory in your classpath C:\Sun\SDK\jdk\bin\java -cp E:\Chap1 source

and remember to supply the output directory for the compiler as well if you don't want to compile to the directory from where you're executing the compile action.

Thanks! I'll give that a try!

...Tyster

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.