java Command: Run JARs & Classes in CI
java starts the JVM and runs a main class or an executable JAR.
The java launcher runs compiled bytecode in CI to execute test runners, code generators, or built application JARs. Its flags select the entry point, set the classpath/module path, and tune heap and system properties.
Common flags
-jar app.jar- run the Main-Class declared in the JAR manifest-cp/-classpath PATH- set the class path (cannot combine with -jar)--module-path/-m mod/Main- run a module on the module path-DpropName=value- set a JVM system property-Xmx2g/-Xms512m- set max / initial heap size-ea- enable assertions (useful in test runs)--add-opens module/pkg=ALL-UNNAMED- open packages for reflection
Example in CI
Run a built Spring Boot fat JAR with a CI profile and bounded heap:
shell
java -Xmx1g -Dspring.profiles.active=ci -jar build/libs/app.jarCommon errors in CI
- Error: Could not find or load main class X - wrong classpath or missing class
- no main manifest attribute, in app.jar - JAR lacks a Main-Class (not an executable JAR)
- java.lang.OutOfMemoryError: Java heap space - raise -Xmx
- java.lang.UnsupportedClassVersionError - JAR built for a newer JDK than the runtime
Key takeaways
-jaruses the manifest Main-Class and ignores-cp; pick one or the other.- Set
-Xmxexplicitly in CI so large test suites do not OOM on shared runners. - UnsupportedClassVersionError means the runtime JDK is older than the build JDK.
Related guides
javac Command: Compile Java in CIjavac is the Java compiler. Reference for -d, -cp/-classpath, --release, -source/-target, -Xlint, and the pac…
mvn Command: Build Maven Projects in CImvn is the Maven build tool. Reference for clean, install, verify, -B, -DskipTests, -P, -pl, and the Maven CI…
gradle Command: Build JVM Projects in CIgradle is the JVM build tool. Reference for build, test, --no-daemon, --build-cache, -x, --stacktrace, and th…