通过批处理脚本执行java程序
我有一个java类“Test.java”,其中包含某些代码。
public class Test {
public static void main(String[] args) throws Exception {
testMount();
}
public static void testMount() throws Exception {
System.out.println(System.getProperty("os.name"));
//Windows
String volumeToMount = "\\\\?\\Volume{****-****-******-********}\\";
String mountPoint = "C:\\temp\\";
mountFileSystem("", "", volumeToMount, mountPoint); //This carries out the operation
}
}
我已经在Linux操作系统中编译了代码。我想通过批处理脚本(.bat 文件)运行编译后的代码。我该怎么做?其语法是什么?如果我必须添加一些外部 jar,我该如何将它们插入到 .bat 文件的语法中?
I have a java class "Test.java" which contains certain code.
public class Test {
public static void main(String[] args) throws Exception {
testMount();
}
public static void testMount() throws Exception {
System.out.println(System.getProperty("os.name"));
//Windows
String volumeToMount = "\\\\?\\Volume{****-****-******-********}\\";
String mountPoint = "C:\\temp\\";
mountFileSystem("", "", volumeToMount, mountPoint); //This carries out the operation
}
}
I have already compiled the code in Linux Operating System. I want to run the compiled code through a batch script ( .bat file). How do i do that? What is the syntax for that? If i have to add some external jars, where and how do I insert them in the syntax within the .bat file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是一个 bat 文件的示例,用于从带有外部 jar 的 jar 中执行 java 代码:
here is an example of bat file for executing a java code from the jar with external jars:
.bat 适用于 Windows;尝试将 Windows 中的 Java 代码编译为 EXE(使用外部库,如 galchen 所建议),然后添加 EXE 名称以及批处理文件的相对/绝对路径。
例如,输出的EXE名为test.exe,批处理文件应包含:
编译为EXE的优点主要是为了性能。
.bat is for Windows; try to compile your Java codes in Windows to EXE (with your external libraries, as suggested by galchen), and add your EXE name along with relative / absolute path to the batch file.
For example, the output EXE is named as test.exe, the batch file should contain:
Advantage of compiling to EXE is mainly for performance.