Introduction to JVM Languages
上QQ阅读APP看书,第一时间看更新

Runnable JAR file

A JAR file can be set up in such a way that it could be started using the java command. This is only possible if the JAR file was configured correctly to allow this. In this case, the JAR file specifies which class contains the main() method that will be run by the java command.

This is a convenient feature for end users, as a single JAR file is completely self-contained:

  • A JAR file contains all the required dependencies
  • Manually setting the ClassPath is not necessary (or even possible) at all
  • A user does not have to manually tell the JVM which class contains the main() method
There are limitations: a runnable JAR file cannot find classes that are not placed inside the JAR file. The usual ClassPath cannot be used by classes inside those JAR files.