This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes java at linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "java at linux" Watch "java at linux" New topic
Author

java at linux

Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
hey folks, i just began to use linux, i'm totally puzzeled, so please help me.
i installed sdk, i want to run a simple java file
which will output "Goodbye, world!"
now, i compile the file and get a class file.
but when i try to run it, i get a ClassNotFound exception: something like /usr/java/jdk1_4_1/World/class not found...
i have no idea why World.class becomse World/class, this is some kind of linux bizzare stuff.
thanX for ya help folks.


Asher Tarnopolski
SCJP,SCWCD
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
You didn't tell us what you were typing to run your new class, but I guess you typed something like:
java World.class
What you really need to type is more like:
java World
The Java interpreter will add the ".class" automatically.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
thank's for your answer.
i tried this too. it doesn't help.
to run the file i type
/usr/local/jdk/bin/java /usr/local/javafiles/World
i still get NoClassDefFound..
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Go to the directory that has World.class in it. Then type:

and tell us what you get.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Java is also really picky about your classpath in Linux.
You need to do one of a couple of things.
1. Explicitly specify your classpath when executing your application.
i.e. java -classpath "directory/of/class/file" World
2. Create an environment variable called CLASSPATH in your .bashrc (for bash shell) file.
i.e.
CLASSPATH=/path/to/class/files
export CLASSPATH


GenRocket - Experts at Building Test Data
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Of course it also depends on WHAT Linux you are running. Linux distributions are not very portable
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15962
    
  19

Actually, the problem is that the current directory is NOT automatically part of the classpath.
try

Did you see the little "."? It means "current directory" in both the Windows/DOS and Unix/Linux worlds (and internal to Java just about anywhere).
You can alternatively export a "CLASSPATH=." in your login script if you like.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
jQuery in Action, 2nd edition
 
subject: java at linux
 
Similar Threads
ajax and java
HelloWorldSwing
Problems with SDK
Editing Environment Variables
core java doubt