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

java command - where should it be called

 
Charles Chikito
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vidmantas Maskoliunas
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic