简体   繁体   English

使用.bat文件运行.jar文件

[英]Running a .jar File Using .bat File

HI Guys I Have A jar File Named Column Reader. 嗨,我有一个名为列读取器的jar文件。 I am trying to Run it using a .bat file that has the Following Script: 我正在尝试使用具有以下脚本的.bat文件运行它:

@echo off
java.exe -jar Column Reader.jar parameter

Can Anyone tell me why it is not Running? 谁能告诉我为什么它没有运行? Because I have Managed t Run Another Jar File Named Nope.jar the same way. 因为我管理过t用相同的方式运行另一个名为Nope.jar的Jar文件。

This is because you have a space in the file name. 这是因为文件名中有空格。 Try instead with: 尝试使用:

java.exe -jar "Column Reader.jar" parameter

Or better still, rename your JAR file to column-reader.jar . 还是更好,将您的JAR文件重命名为column-reader.jar Generally JAR files are named in all lowercase, often without any spaces in the file names. 通常,JAR文件以小写命名,通常在文件名中没有空格。

Some examples of proper JAR file names: 正确的JAR文件名的一些示例:

org.springframework.web.struts-3.1.1.RELEASE.jar
poi-ooxml-schemas.jar
slf4j-api.jar
soap.jar

You need to make sure that the command line knows where java.exe , and Column Reader.jar are. 您需要确保命令行知道java.exeColumn Reader.jar位置。 Also, you need to put anything that goes together in quotes, so it would be "Column Reader.jar" . 另外,您需要将所有一起放在引号中,因此它将是"Column Reader.jar" You may need to point directly to the jar like this: 您可能需要像这样直接指向罐子:

java -jar "C:\\Your\\directory\\Column Reader.jar" parameter

To avoid the quotes you can just make sure the path doesn't contain any spaces. 为了避免使用引号,您只需确保路径不包含任何空格即可。 Also, if you want to point to a specific java.exe file you can do: 另外,如果要指向特定的java.exe文件,则可以执行以下操作:

C:\\Program Files\\Java\\jre7\\bin\\java.exe -jar C:\\Your\\directory\\column-reader.jar parameter

You don't have to be so explicit if your environment variable for java ( JAVA_HOME ) is set and if your .bat file is in the same directory as your .jar 如果设置了Java( JAVA_HOME )环境变量,并且.bat文件与.jar位于同一目录中,则不必太明确

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM