This question already has an answer here:
这个问题在这里已有答案:
- call java class in batch file 5 answers
- 在批处理文件中调用java类5个答案
I need to run my Java Application through .bat file. Can anybody help please.
我需要通过.bat文件运行我的Java应用程序。请有人帮忙吗?
8 个解决方案
#1
28
Simply create a .bat file with the following lines in it:
只需创建一个.bat文件,其中包含以下行:
@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
12
Sure, call the java executable.
当然,调用java可执行文件。
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,所以要运行它我会这样做
C:\Program Files\Java\jre6\bin\java.exe -jar myjarfile.jar
C:\ Program Files \ Java \ jre6 \ bin \ java.exe -jar myjarfile.jar
#3
6
It's the same way you run it from command line. Just put that "command line" into a ".bat" file.
它与从命令行运行它的方式相同。只需将“命令行”放入“.bat”文件即可。
So, if you use java -cp .;foo.jar Bar
, put that into a .bat file as
因此,如果您使用java -cp。; foo.jar Bar,请将其放入.bat文件中
@echo off
java -cp .;foo.jar Bar
#4
3
@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.
1)打开一个notpad 2)复制并通过此代码并保存此文件为ex:test.bat 3)双击tha批处理文件。 4)将你的java代码放入记事本并保存为N.B.:-保存这个java文件与批处理文件存在的文件夹相同。
#5
2
If You have jar file then create bat file with:
如果您有jar文件,则使用以下命令创建bat文件:
java -jar NameOfJar.jar
#6
2
javac Application.java
javac Application.java
java Application
java应用程序
pause
暂停
The javac
command will compile the java program and the java
command will run the program and pause
will pause the result until you cross it.
javac命令将编译java程序,java命令将运行程序,暂停将暂停结果,直到您跨过它。
#7
0
Call the class which has main() method.
调用具有main()方法的类。
java MyClass
java MyClass
Here MyClass will have public static void main()
method.
这里MyClass将有public static void main()方法。
#8
0
-
javac (.exe on Windows) binary path must be added into global PATH env. variable.
必须将javac(Windows上的.exe)二进制路径添加到全局PATH环境中。变量。
javac MyProgram.java
javac MyProgram.java
-
or with java (.exe on Windows)
或者使用java(Windows上的.exe)
java MyProgram.jar
java MyProgram.jar
#1
28
Simply create a .bat file with the following lines in it:
只需创建一个.bat文件,其中包含以下行:
@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
12
Sure, call the java executable.
当然,调用java可执行文件。
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,所以要运行它我会这样做
C:\Program Files\Java\jre6\bin\java.exe -jar myjarfile.jar
C:\ Program Files \ Java \ jre6 \ bin \ java.exe -jar myjarfile.jar
#3
6
It's the same way you run it from command line. Just put that "command line" into a ".bat" file.
它与从命令行运行它的方式相同。只需将“命令行”放入“.bat”文件即可。
So, if you use java -cp .;foo.jar Bar
, put that into a .bat file as
因此,如果您使用java -cp。; foo.jar Bar,请将其放入.bat文件中
@echo off
java -cp .;foo.jar Bar
#4
3
@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.
1)打开一个notpad 2)复制并通过此代码并保存此文件为ex:test.bat 3)双击tha批处理文件。 4)将你的java代码放入记事本并保存为N.B.:-保存这个java文件与批处理文件存在的文件夹相同。
#5
2
If You have jar file then create bat file with:
如果您有jar文件,则使用以下命令创建bat文件:
java -jar NameOfJar.jar
#6
2
javac Application.java
javac Application.java
java Application
java应用程序
pause
暂停
The javac
command will compile the java program and the java
command will run the program and pause
will pause the result until you cross it.
javac命令将编译java程序,java命令将运行程序,暂停将暂停结果,直到您跨过它。
#7
0
Call the class which has main() method.
调用具有main()方法的类。
java MyClass
java MyClass
Here MyClass will have public static void main()
method.
这里MyClass将有public static void main()方法。
#8
0
-
javac (.exe on Windows) binary path must be added into global PATH env. variable.
必须将javac(Windows上的.exe)二进制路径添加到全局PATH环境中。变量。
javac MyProgram.java
javac MyProgram.java
-
or with java (.exe on Windows)
或者使用java(Windows上的.exe)
java MyProgram.jar
java MyProgram.jar