且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在使用JAR运行spark-submit时将程序参数传递给main函数?

更新时间:2022-03-02 18:39:48

参数传递之前 .jar文件将是JVM的参数,之后的参数将jar文件传递给用户程序。

Arguments passed before the .jar file will be arguments to the JVM, where are arguments after the jar file will be pass on to the users program.

bin/spark-submit --class classname -Xms256m -Xmx1g something.jar someargument

此处, s 将等于 someargument ,其中 - Xms -Xmx 被传递到JVM。

Here, s will equal someargument, where the -Xms -Xmx are passed into the JVM.

public static void main(String[] args) {

    String s = args[0];
}