The java launcher allows other flags to appear between -jar and its argument.
The following example shows that `java -jar hello.jar` and `java -jar -Xmx2g hello.jar` have equivalent behaviour, where in the second example the launcher scans past other arguments to find the jar file argument to `-jar`.
https://docs.oracle.com/en/java/javase/23/docs/specs/man/java.html suggests that the jarfile should immediately follow -jar:
> java [options] -jar jarfile [args ...]
...
> -jar jarfile
> Executes a program encapsulated in a JAR file. The jarfile argument is the name of a JAR file with a manifest that contains a line in the form Main-Class:classname that defines the class with the public static void main(String[] args) method that serves as your application's starting point. When you use -jar, the specified JAR file is the source of all user classes, and other class path settings are ignored. If you're using JAR files, then see jar.
$ java -fullversion
openjdk full version "24-ea+15-1658"
$ cat Hello.java
class Hello {
public static void main(String[] args) {
System.err.println("hello world");
}
}
$ javac Hello.java
$ jar cvfe hello.jar Hello Hello.class
$ java -jar hello.jar
hello world
$ java -jar -Xmx2g hello.jar
hello world
The following example shows that `java -jar hello.jar` and `java -jar -Xmx2g hello.jar` have equivalent behaviour, where in the second example the launcher scans past other arguments to find the jar file argument to `-jar`.
https://docs.oracle.com/en/java/javase/23/docs/specs/man/java.html suggests that the jarfile should immediately follow -jar:
> java [options] -jar jarfile [args ...]
...
> -jar jarfile
> Executes a program encapsulated in a JAR file. The jarfile argument is the name of a JAR file with a manifest that contains a line in the form Main-Class:classname that defines the class with the public static void main(String[] args) method that serves as your application's starting point. When you use -jar, the specified JAR file is the source of all user classes, and other class path settings are ignored. If you're using JAR files, then see jar.
$ java -fullversion
openjdk full version "24-ea+15-1658"
$ cat Hello.java
class Hello {
public static void main(String[] args) {
System.err.println("hello world");
}
}
$ javac Hello.java
$ jar cvfe hello.jar Hello Hello.class
$ java -jar hello.jar
hello world
$ java -jar -Xmx2g hello.jar
hello world