• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Classpath Problems

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just downloaded and installed the JDK1.50_06 with net beans 4.1 in Windows XP on a 2.0GHz AMD-64 Machine. I decided to try to write my first java code in an editor and execute from the command line. I get the error "Exception in thread "main" java.lang.NoClassDefFoundError:". Supposedly this problem is caused by not having the CLASSPATH set correctly, so I dutifully add . and the full path to the directory where my HelloWorldApp.class file is located to the user and system CLASSPATH environment variables and reboot. The error message is the same. I decide to reboot into SuSE Linux 10.0 where I have installed the linux version of the JDK/IDE into my home directory. I add the appropriate paths to the PATH and CLASSPATH variables in bash.rc w/ export statement (This is where you set Environment Variables for individual users in SuSE 10.0)and reboot. When I try to run the app I get the same error message as in Windows. Any suggestions as to why this might be happening? Is this problem somehow caused by the IDE?

Thanks for your time.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1- Get rid of the CLASSPATH system environment variable. It could cause you a lot of problems.
2- When you compile using javac, set the class path with -classpath command-line argument. From the command prompt:
> javac -classpath someFolder;someJar;someZip SomeClass.java

By the way, if you don't specify the -classpath command-line argument and there is NO CLASSPATH environment variable set, then the class path is the current working directory. Exactly like doing:
> javac -classpath . SomeClass.java

Regards
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please see this post.
 
Joe Scholbotnick
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestion Jean-Francois, but I am still having the same problem. As you suggested got rid of the system CLASSPATH environment variable.

My environment variables are currently set as follows:
user CLASSPATH {.;C:\1java}
user PATH {C:\Program Files\Java\jdk1.5.0_06\bin}
system CLASSPATH - deleted
system Path {SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\Python22;C:\Program Files\PC-Doctor for Windows\services;c:\matlab_sv13\bin\win32;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Java\jdk1.5.0_06\bin}
the system Path is just that Path, not PATH I assume that is correct?

my HelloWorldApp.java and HelloWorldApp.class are in C:\1java\
my windows java installation is in C:\Program Files\Java\jdk1.5.0_06\bin\

In order to eliminate the possibility that the code was incorrect I downloaded the example file from java.sun.com

First I compiled using :
C:\1java>javac HelloWorldApp.java
and then attempted to run using
C:\1java>java HelloWorldApp.class
only to receive "Exception in thread "main" java.lang.NoClassDefFoundError:"

I deleted the .class file and tried to compile using
C:\1java>javac -classpath . HelloWorldApp.java
and then try to run, same error

I deleted the .class file and tried to compile using
C:\1java>javac -classpath C:\1java HelloWorldApp.java
and then try to run, same error

Some other potentially useful information.
There are two older jre installations in the Java folder
jre1.4.1_02 and jre1.4.2
There is a system environment variable QTJAVA {C:\Program Files\Java\j2re1.4.2\lib\ext\QTJava.zip} (which I assume has to do with Quicktime)
I installed jdk1.5.0_06 with the netbeans 4.1 bundle.
I am running on an AMD Athalon 64 processor.
I am running Windows XP Home Edition 2002 version SP2 or SuSE 10.0 Linux

My suspicion is that this problem is a side effect of installing the IDE. I may try to uninstall the bundle and re-install without netbeans, but since I am on dialup downloading is six hour long process and won't happen immediately.

I am still having the exact same problem in my Linux installation.

I am going to try to learn how to use Netbeans to see if I can run code from there, but I was hoping to avoid having to learn how to use the IDE at the same time as learning the language. The first page of the netbeans manual does say "readers of this guide are assumed to have at least a basic understanding of the Java programming language and related technologies."
which doesn't excite me considering I am at the HelloWorldApp stage.

Thanks again for your help.
 
Joe Scholbotnick
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link wise ou. The respondant to this post does seem to be saying the same thing that Jean-Francois Briere did about setting the classpath manually. Still the fact that the original poster was able to run in the IDE (Eclipse in his case) does suggest that it may be related to both his and my problems.
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a Windows XP command prompt, please do the following:
> javac -version

Then do:
> java -version

Are the versions the same?

Also, when you run the program, please also use the -classpath command-line argument (exactly like javac):
> java -classpath c:\1java HelloWorldApp

By the way, you didn't get rid entirely of CLASSPATH (user environment variable).

Regards
 
Joe Scholbotnick
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jean-Francois, thanks for the suggestions, but I figured out the cause of the problem.

I went back and re-read the tutorial for the eighth time and noticed what I have been missing.

It seems I am the victim of the tab key. I am so used to using tab to auto complete in the linux bash shell that it didn't occur to me that when I type

C:\1java>java He (Tab)
and get
C:\1java>java HelloWorldApp.class
that It wouldn't run properly if I just hit enter.

C:\1java>java HelloWorldApp

without .class does the trick

in linux if you type $tar -zxvf He (tab) to unpack the tarball HelloWorldApp.tar the bash shell knows that you want HelloWorldApp.tar and not HelloWorldApp.rpm which happens to be in the same directory and autocompletes with the correct file for the command you typed. It doesn't surprise me that this misfires in windows, but it does surprise me that it happened in linux too.

Thanks again for the help, sorry for wasting your time. FWIW I did try to do my homework before posting here.
 
reply
    Bookmark Topic Watch Topic
  • New Topic