| Author |
Very beginner question regarding path
|
Max Benjamin
Greenhorn
Joined: Apr 12, 2006
Posts: 13
|
|
I'm just trying to get started with Java and have run into some difficulties already. I think the problem is that I haven't set the environment path correctly. When I attempt to run a short program(from the headfirst java book) I get the following error: Welcome to Darwin! Max-Bejnamins-Computer:~ maxbenjamin$ java /Users/maxbenjamin/Desktop/BeerSong.class Exception in thread "main" java.lang.NoClassDefFoundError: /Users/maxbenjamin/Desktop/BeerSong/class I tried to set the PATH variable by altering the /private/etc/profile to: # System-wide .profile for sh(1) PATH="/bin:/sbin:/usr/bin:/usr/sbin:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/bin" export PATH [ -r /etc/bashrc ] && source /etc/bashrc I'm on OSX 10.3.9 using the bash shell. If anyone could help me out I'd be very thankful.
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
First thing you have to know is that you don't need to specify ".class" when running the program. Try again with : java /Users/maxbenjamin/Desktop/BeerSong
|
[My Blog]
All roads lead to JavaRanch
|
 |
Rodrigo Alvarez
Ranch Hand
Joined: Apr 10, 2006
Posts: 75
|
|
Hi Max, welcom in the wonderful world of Java try to : cd /Users/maxbenjamin/Desktop/ then : java nameOfTheApplicationWithDotClass note that this assumes that you are using the default package (i.e. not "package" keyword at the beginnig of the .java file). If you file were using the package "name.of.the.package" and were name "app.java", you would have to: * put this line in the very beginning of the java file: package name.of.the.package * create the directory /Users/maxbenjamin/Desktop/name/of/the/package * put the java file in /Users/maxbenjamin/Desktop/name/of/the/package * compile it * cd /Users/maxbenjamin/Desktop/ * execute : java name.of.the.package.app Cheers
|
It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
|
 |
Rodrigo Alvarez
Ranch Hand
Joined: Apr 10, 2006
Posts: 75
|
|
java nameOfTheApplicationWithDotClass
oups, sorry , I meant WITHOUT the .class, so BeerSong in your case
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Max Benjamin: ...I'm on OSX 10.3.9 using the bash shell...
Welcome to JavaRanch! Macs come ready to go for Java, so you shouldn't need to change any path settings. Also, I wouldn't complicate things with packages until you get to that point in the book. For now... Change the directory (cd) to where your Java files are (this will save you some command line typing).Compile with javac, including the .java extension on the file name.Run with java, using no extension on the file name. (I think this was your original problem.)...$ cd /Users/maxbenjamin/Desktop ...$ javac BeerSong.java ...$ java BeerSong Also note that we have a Mac OS forum for Mac-specific Java questions. I'll move this post there for you. [ April 12, 2006: Message edited by: marc weber ]
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
 |
|
|
subject: Very beginner question regarding path
|
|
|