[英]batch file to run jar file with parameters
How can I run a batch file and pass parameters to jar file?如何运行批处理文件并将参数传递给 jar 文件?
this doesn't work这不起作用
mybat.bat我的蝙蝠.bat
java -jar log_parser.jar %1 %2 %3 %4
running bat file运行bat文件
C:\>log_parser.bat -file=C:\\trace_small.log -str=Storing
java sees only -file
java 只看到-file
I just tried with a small java program that only dumps the arguments to the screen:我刚刚尝试了一个小的 java 程序,它只将 arguments 转储到屏幕上:
public static void main(String[] args)
{
for(String s : args)
{
System.out.println(s);
}
}
and the following batch file:和以下批处理文件:
java -jar test.jar %1 %2 %3 %4
and I ended up with the following result我最终得到了以下结果
-file
C:\\trace_small.log
-str
Storing
For the same command line as you... the equal sign '=' desapeared.对于与您相同的命令行...等号“=”消失了。 Now if you trun the batch file to this:现在,如果您将批处理文件改为:
java -jar test.jar %*
you will get yet another result (which might be what you expected - not clear)你会得到另一个结果(这可能是你所期望的 - 不清楚)
-file=C:\\trace_small.log
-str=Storing
The advantage on this %* syntax, is that it is more extensible by accepting any number of arguments.这种 %* 语法的优势在于,它通过接受任意数量的 arguments 具有更高的可扩展性。
Hope this helps, but I recommend you to have a look at your code to and add some debug statement to understand where you are "lossing" some part of the input.希望这会有所帮助,但我建议您查看您的代码并添加一些调试语句,以了解您在哪里“丢失”了输入的某些部分。
In my case I use the following bat-file:就我而言,我使用以下 bat 文件:
@echo off
PATH_TO_JRE\bin\java.exe -jar -Denable=true your_file.jar
At this particular case then in java code I can get the param "enable" like this:在这种特殊情况下,然后在 java 代码中,我可以像这样获得参数“启用”:
Boolean.getBoolean("enable")
For Example Opening Street Map Editor in Windows 10 x64例如,Windows 10 x64 中的 Open Street Map 编辑器
> cd "C:\Program Files\Java\jre1.8.0_161\bin\"
> javaw.exe -Xmx2048m -jar "C:\Program Files (x86)\JOSM\josm-tested.jar"
1) You could try to use 1)你可以尝试使用
"-Dfile=C:\trace_small.log -Dstr=Storing" “-Dfile=C:\trace_small.log -Dstr=存储”
The variables would be set as Java System Property, but not as Parameters into a main-method.变量将被设置为 Java 系统属性,而不是作为参数进入主方法。
2) Try to put the arguments without '=' 2)尝试把arguments不带'='
log_parser.bat -file C:\trace_small.log -str Storing log_parser.bat -file C:\trace_small.log -str 存储
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.