将参数传递给在bat文件中调用的jar文件?
我创建了一个需要在bat 文件中调用的jar。我需要将 bat 文件收到的所有命令行参数传递给 jar。谁能帮我一下。我知道这是一个愚蠢的问题,但我对 jar 和 bat 没有任何想法。在网上我无法找到两者的组合。另请注意,我不知道如何检索 bat 文件中的命令行参数。
I have created a jar which needs to be called in a bat file. I need to pass all the command line arguments recieved by bat file to the jar. Can anyone please help me out. I know this is a stupid question, but i dont have any idea about jar and bat. On net i am unable to find the combination of both. Also note that i dont know how to retieve the command line arguments in the bat file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过以下方式访问传递给批处理文件的参数,
因此,如果您像这样调用批处理
,则批处理文件中的 java 调用应如下所示:
The parameters that you pass to your batch file can be accessed via
So if you call your batch like
then your java call inside the batch file should look like:
在你的bat文件中你将有
java
命令只需使用
java -jar helloworld.jar firstParam secondaryParam
和我相信您也可以使用,因为我们如何将参数传递给
Maven
和ANT
等等Inside you bat file you will have
java
commandjust use
java -jar helloworld.jar firstParam secondParam
andI believe you can also use because that how we pass params to
Maven
andANT
etc如果您不知道用户可以传递多少参数到批处理文件(如果有),您需要获取编号。无论用户传递了什么参数,只需在开始时将以下代码片段添加到您的 main 方法中
您可以将所有参数存储在 Arraylist 中以使用它并稍后对其进行迭代
If you don't know how many parameters the users could pass to the batch file (if any) you need to get the no. of arguments whatever the user has passed, simply add the following snippet to your main method at the start
You can store all the arguments in an Arraylist to use it and iterate over it later