Two Laptop Bag*
The moose likes Beginning Java and the fly likes running java command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "running java command" Watch "running java command" New topic
Author

running java command

vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
i am in my /work/vsubra/test directory and i have a file here as aigemail.java
Now when i run the javac and java command from this dir everything runs okay.
if i try to run the java command as
java /work/vsubra/test/aigemail then it throws error:
Exception in thread main "no class defn found"
why does it give me error when i try the wholepath.
what is an option if i want to give the whole path?
thanks
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Hi Vidhya,
If your file "aigemail.java" is not in a package (i.e. the first, non-comment line in your class starts with "package"), then you run it like this:

Hope this helps you.
Good Luck,
Avi.
vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
I think you have mistaken me wrong. This file aigemail.java is in the directory /work/vsubra/test. I would like to execute it from anywhere, so if i have to do that then i will have to specify the full path where the file is. if i give
java /work/vsubra/test aigemail
it gives me an error
Exception in thread main no class found: /work/vsubra/test.
how can i fix this ?
Thanks,
Vidhya
Gopi Balaji
Ranch Hand

Joined: Jan 23, 2003
Posts: 84
Originally posted by vidhya subramaniam:
I think you have mistaken me wrong. This file aigemail.java is in the directory /work/vsubra/test. I would like to execute it from anywhere, so if i have to do that then i will have to specify the full path where the file is. if i give
java /work/vsubra/test aigemail
it gives me an error
Exception in thread main no class found: /work/vsubra/test.
how can i fix this ?
Thanks,
Vidhya

Try
.
If your Java class includes additional APIs, then on Unix machines try -

When you use
[CODEjava /work/vsubra/test/aigemail[/CODE], the Java VM looks for a class in the current directory, with its fully qualified name as
work.vsubra.test.aigemail, which is not present, and that is why the ClassNotFoundError.
-GB.
vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
Can you be more specific. My class path is set as
/work/vsubra. I i go to test dir within this dir and run java aigemail, it runs fine but i want to run from my home dir ie /work/vsubra
I tried giving
java -classpath /work/vsubra:/work/vsubra/test aigemail
but still it gives me runtime error.
Gopi Balaji
Ranch Hand

Joined: Jan 23, 2003
Posts: 84
What packages do the aigemail classes import?
Is aigemail in a non-default pakckage (i.e, is there a package declaration in the aigemail.java file) ?
Try this - java -classpath $CLASSPATH:/work/vsubra/test aigemail
It looks like I added another $ sign previously.
-GB.
vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
Thanks,
Balaji... it worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running java command