• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

running java command

 
vidhya subramaniam
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
Balaji... it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic