Link to home
Create AccountLog in
Avatar of Arun_Jain504
Arun_Jain504

asked on

Java Virtual Machine

In java How can you execute a class file using
window's "java.exe" and not sun's java VM.
Avatar of Leo Eikelman
Leo Eikelman

java.exe -classpath . HelloWorld

Leo
Also, extended examples

To run a HelloWorld.class app, in the default package in a jar in C:\MyDir, use
java.exe -jar HelloWorld.jar HelloWorld

To run a HelloWorld.class app in C:\com\mindprod\mypackage, in package com.mindprod.mypackage, use
java.exe -classpath . com.mindprod.mypackage.HelloWorld

This will not work to run a HelloWorld.class app in C:\com\mindprod\mypackage, in package com.mindprod.mypackage:
C:\com\mindprod\mypackage
java.exe -classpath . com.mindprod.mypackage.HelloWorld
For that to work, you must use smartj instead of java.exe.

To run a HelloWorld.class app in C:\com\mindprod\mypackage, in a jar in package com.mindprod.mypackage, use
CD \AnyDir
java.exe -jar HelloWorld.jar com.mindprod.mypackage.HelloWorld

If for any reason the examples shown do not work with your version of java.exe, try various combinations of
com.mindprod.mypackage.HelloWorld, com/mindprod/mypackage/HelloWorld and com\mindprod\mypackage\HelloWorld.

Cheers,

Leo
You need to either explicitly specify the path of the java.exe that you wish to use, or alter the system's PATH variable..
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer