How to set the -Xmx when start running a jar file?

后端 未结 5 1890
青春惊慌失措
青春惊慌失措 2020-12-13 12:36

As we know that we can set -Xmx1024M in window->preferences->java->installed jres->edit->default vm arguments in eclipse

5条回答
  •  囚心锁ツ
    2020-12-13 13:30

    Unfortunately, existing answers are wrong in one crucial point.

    -Xmx must be passed to the Java runtime environment, not to the executed jar.

    Wrong:

    java -jar JavaApplication.jar -Xmx1024m 
    

    Correct:

    java -Xmx1024m -jar JavaApplication.jar 
    

    More specifically, the java launcher needs to be used as follows:

    java [options] -jar file.jar [arguments]

    • [options] are passed to the Java runtime environment
    • [arguments] are passed to the main function

    The -Xmx parameter belongs to the (nonstandard) JVM options, and--being an option--needs to be listed before -jar (or at least before file.jar). The JVM will not recognize an -Xmx argument passed to the main function as proposed in other answers.

提交回复
热议问题