File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes commands for java.exe in DOS? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "commands for java.exe in DOS?" Watch "commands for java.exe in DOS?" New topic

commands for java.exe in DOS?

Kevin Schneider

Joined: Oct 16, 2003
Posts: 10
i know how to create a batch file that simply says
"java Main.class"
and it runs the java program fine on my machine, but only if it doesnt have a package statement. lets say my package statement is "com.javaranch" what EXACTLY would my batch file look like? i'm unfamiliar with dos commands.
thanks much!
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Hi Kevin,
Welcome to JavaRanch!
Note that "java Main.class" isn't going to work; "java Main" is correct.
If Main is in a package, you just need to say "java com.javaranch.Main".
Both of these assume that Main.class, or com/javaranch/Main.class, are on your CLASSPATH.

[Jess in Action][AskingGoodQuestions]
Kevin Schneider

Joined: Oct 16, 2003
Posts: 10
hey thanks for the reply. i tried what you said, but this is the error i get at the DOS prompt:
Exception in thread "main" java.lang.NoClassDefFoundError: edu/uwec/cs/schneidr/networkTest/Client
but when i just compile and run the program in eclipse there are no problems at all. anyone know what i'm doing wrong?
thanks again
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
try to use java -cp . Main, this means you add the actual path to
your classpath. So edu should then be a subfolder of your actual directory.
Then java should be able to find the required classes
Kevin Schneider

Joined: Oct 16, 2003
Posts: 10
well i've been doing all of this within a batch file...and i've been placing the batch file in the same dir as the actual class files. however i just moved the batch file to the root director (root of the package) and now it works perfectly. i guess thats where the problem was. thanks for all of the help guys.
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
This seems to be related on how to get Java running in a DOS/Windows environment. I'm moving it to Java in General (beginning).

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: commands for java.exe in DOS?
It's not a secret anymore!