Skip to content
Latchkey

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.jar

Common 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

  • -jar uses the manifest Main-Class and ignores -cp; pick one or the other.
  • Set -Xmx explicitly 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →