This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

commands for java.exe in DOS?

 
Kevin Schneider
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
kevin
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kevin Schneider
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic