Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run java application by .bat file [duplicate]

Tags:

I need to run my Java Application through .bat file. Can anybody help please.

like image 912
vivek Avatar asked Jan 20 '12 09:01

vivek


People also ask

How do I run a java program from a batch file?

1)open a notpad 2)copy and past this code and save this file as ex: test. bat 3)Double Click tha batch file. 4)put your java codes into the notepad and save it as N.B.:- save this java file same folder that your batch file exists. what's the purpose of opening up notepad when you just want to compile and run?

How do I run multiple batch files?

bat file to run multiple . bat files independent from each other in their own directories. Try cd to each directory in turn then run the batch file ...

How do I run a jar file from a batch file?

If you want to keep your jar file and bat file in different locations then you need to provide the relative location of your jar file. Now, we can run the batch file by double-clicking on HelloWorld. bat file. When we double click on the bat file, then it should automatically start a jar file.

Is bat file and batch file same?

BAT is the batch file that is used in DOS, OS/2 and Microsoft Windows. CMD files are newer version came into existence for batch files. The older systems will not know about CMD files and will run them partially which will throw an error for the batch files saved as CMD.


2 Answers

Simply create a .bat file with the following lines in it:

@ECHO OFF set CLASSPATH=. set CLASSPATH=%CLASSPATH%;path/to/needed/jars/my.jar  %JAVA_HOME%\bin\java -Xms128m -Xmx384m -Xnoclassgc ro.my.class.MyClass 
like image 89
panagdu Avatar answered Sep 30 '22 09:09

panagdu


Sure, call the java executable.

Mine is C:\Program Files\Java\jre6\bin\java.exe, so to run it I would do

C:\Program Files\Java\jre6\bin\java.exe -jar myjarfile.jar

like image 20
A T Avatar answered Sep 30 '22 09:09

A T