File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "java at linux" Watch "java at linux" New topic

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
Frank Carver

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 ~ 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

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: 15302

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.

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

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: 17417

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

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.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: java at linux
It's not a secret anymore!