批处理文件来运行参数的jar文件 [英] batch file to run jar file with parameters

查看:145
本文介绍了批处理文件来运行参数的jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何运行一个批处理文件,并传递参数的jar文件?

How can I run a batch file and pass parameters to jar file?

这不工作

mybat.bat

java -jar log_parser.jar %1 %2 %3 %4

运行批处理文件

C:\>log_parser.bat -file=C:\\trace_small.log -str=Storing

Java的只能看到 -file

推荐答案

我只是想用一个小型的Java程序,只有转储参数屏幕:

I just tried with a small java program that only dumps the arguments to the screen:

public static void main(String[] args)
{
    for(String s : args)
    {
        System.out.println(s);
    }
}   

和以下批处理文件:

java -jar test.jar %1 %2 %3 %4

和我结束了以下结果。

-file
C:\\trace_small.log
-str
Storing

有关相同的命令行,你...等号=desapeared。
现在,如果你真理的批处理文件,以这样的:

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.

希望这会有所帮助,但我建议你看看你的code并添加一些调试语句来了解你在哪里损耗输入的某些部分。

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.

这篇关于批处理文件来运行参数的jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆