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

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)