Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java at linux

 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go to the directory that has World.class in it. Then type:

and tell us what you get.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course it also depends on WHAT Linux you are running. Linux distributions are not very portable
-Barry
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18154
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic