File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes run java code through bat file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "run java code through bat file" Watch "run java code through bat file" New topic
Author

run java code through bat file

nancy andrew
Ranch Hand

Joined: Jan 19, 2010
Posts: 30
I want to run a java standalone program using a batch file. How can i do it
nancy andrew
Ranch Hand

Joined: Jan 19, 2010
Posts: 30
I tried running through the following code in batch file. But nothing happens.



Can anyone please tell what to modify or change in the above
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3883
    
  18

Well, if you're running a jar file, you should probably include the .jar extension.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20044
    
  30

That's not a JAR file on line 6, is it?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
nancy andrew
Ranch Hand

Joined: Jan 19, 2010
Posts: 30
I dont want to make jar file . I want to run my java file. I got that piece of code through internet. That is wrong and not working. Kindly tell me how to correct it. There is a simple HelloWorld.java standalone program. I want to run it using batch file
Alpesh Gediya
Greenhorn

Joined: Nov 23, 2009
Posts: 24
at line 6 use following instruction

java "path to location in which helloworld.class present"/Helloworld (do not include .class)


Alpesh Gediya
Do not re-invent the wheel.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20044
    
  30

No, definitely not. It's
Alpesh Gediya
Greenhorn

Joined: Nov 23, 2009
Posts: 24
Rob Prime wrote:No, definitely not. It's


You are right Rob,
In hurry forgot to put -cp in command.

Thanks for correction.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14911
    
  26

Also note, that since the paths contain spaces, you must enclose them in quotes:

set JAVA_HOME="C:\Program Files (x86)\Java\jdk1.5.0_09"
set PATH="C:\Windows;C:\Windows\System32;C:\Program Files (x86)\Java\jdk1.5.0_09\bin"


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: run java code through bat file
 
It's not a secret anymore!