I need to run my Java Application through a .bat file.
8 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

- 2,133
- 1
- 21
- 36
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

- 13,008
- 21
- 97
- 158
-
3That should be `java -jar myjarfile.jar` (your example is missing the `-jar`) – Feb 18 '13 at 17:54
It's the same way you run it from command line. Just put that "command line" into a ".bat" file.
So, if you use java -cp .;foo.jar Bar
, put that into a .bat file as
@echo off
java -cp .;foo.jar Bar

- 61,315
- 23
- 138
- 167
@echo off
echo You Are going to creata Java Class
set /p Name=Enter your Class Name?:
echo Your class Name is %Name% & pause
echo To creat a Notepad
pause
notepad %Name%.java
set path=%PATH%;C:\Program Files\Java\jdk1.6.0_14\bin
pause
javac
echo Your java Path succsussfully set.
javac %Name%.java
pause
echo Successfully Compiled
java %Name%
pause
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.

- 744
- 5
- 15
-
3what's the purpose of opening up notepad when you just want to compile and run? – Faahmed Mar 29 '14 at 20:37
Call the class which has main() method.
java MyClass
Here MyClass will have public static void main()
method.

- 1,549
- 2
- 15
- 31
javac (.exe on Windows) binary path must be added into global PATH env. variable.
javac MyProgram.java
or with java (.exe on Windows).
java MyProgram.jar