如何将命令行参数传递给 Spring Batch

How to pass command line arguments to Spring Batch

这是我第一次处理 spring 批处理项目。所以我需要知道如何将参数传递给 .sh 文件中的 main class 。该项目目前正在运行,.sh 文件有一个命令行,如下所示:

java -Xmx2048M -jar somebatch-SNAPSHOT.jar applicationContext.xml

我想通过更改此命令来传递参数。项目 运行 在主要 class 中包含所有作业,因此未在命令中指定作业名称。我想做的是传递参数,这样我就可以 select 哪些工作会 运行。像这样:

java -Xmx2048M -jar somebatch-SNAPSHOT.jar --argument 1 applicationContext.xml

我不需要像 java -jar somejar.jar somejob value=1 那样将参数传递给 jobParameters,如某些示例所示。我只需要 main class.

中的一个值

感谢任何帮助。

I don't need to pass the arguments to the jobParameters like java -jar somejar.jar somejob value=1 as shown in some examples. I only need a value in the main class.

在这种情况下,您可以使用 -Dparam=value 在命令行上传递参数,然后使用 System.getProperty("param").

在主 class 中获取它们