将传递的参数重定向到 Windows 批处理文件

将传递的参数重定向到 Windows 批处理文件

问题描述:

我想从 Windows 批处理文件中调用 jar 文件.一项要求是能够将所有批处理文件参数按原样传递给 jar 文件调用.例如,

I would like to call a jar file from a windows batch file. One requirement is to be able to pass all the batch file arguments as-is to the jar file invocation. For example,

必需的命令行:

foo.bat --flag1=x --flag2=y --flag3=z

批处理文件 foo.bat 应该调用 foo.jar 如下:

The batch file foo.bat should invoke foo.jar like follows:

java -jar foo.jar --flag1=x --flag2=y --flag3=z

如何使批处理文件执行此操作?
我可以用 % 做一些批处理变量魔术来做到这一点,但有没有更简单的方法来做到这一点?

How do I make the batch file do this?
I can do some batch variable magic with % to do this, but is there a simpler way to do this?

java -jar foo.jar %*

满足您的需求?它应该将批处理执行中的所有参数添加到批处理文件中的应用程序调用中.

meet your needs? It should add all parameters from the batch execution to your application call within the batch file.