my dog learned polymorphism*
The moose likes Java in General and the fly likes java command - where should it be called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java command - where should it be called" Watch "java command - where should it be called" New topic
Author

java command - where should it be called

Charles Chikito
Ranch Hand

Joined: May 22, 2009
Posts: 76
Hi there,

I believe java command is used to invoke the JVM and run the .class file.
I have set the path to bin directory in the environment variables (under Windows System Utilities) and able to call javac command from anywhere but not the java.

I can only call the java command from the same directory where the .class file is. Is it because of the security reason?

Thanks

_charles
Rok Štelcer
Ranch Hand

Joined: Nov 03, 2009
Posts: 101
Hi,

Chikito Charles wrote:I believe java command is used to invoke the JVM and run the .class file.
I have set the path to bin directory in the environment variables (under Windows System Utilities) and able to call javac command from anywhere but not the java.

After setting the PATH, you should restart the cmd(s) in order for new PATH to be used.

Chikito Charles wrote: Is it because of the security reason?

No, this has nothing to do with security.


Regards,
Rok


SCJP, SCWCD
Vidmantas Maskoliunas
Greenhorn

Joined: Nov 16, 2009
Posts: 22
Hi,

if you can call the "javac" command then check if the .../bin contains java.exe as well.

Also, give us the error message that appears when you try to call java from the directory other than containing .class files.

Probably you mean "I can call java, but it does not execute my program", right?

If yes, then you need to check the package of the class that you are trying to pass as parameter. If it lies in default package (i.e. no package is set explicitly), then yes -- you cannot execute it from any outside directory.

But for example, put the class into "com.example.java.test" package (declare "package com.example.java.test" in the source code) and have the following directory structure with the compiled classfile:
C:\mycode\com\example\java\test\MyClass.class

You will need to call the java command from C:\mycode by typing the following command line
java com.example.java.test.MyClass

Does it work?


SCJP 6.0, willing to find Java job in NZ/AU and move there - LinkedIn profile - Java blog
 
jQuery in Action, 2nd edition
 
subject: java command - where should it be called