Java - (Main|Start) Class

> Procedural Languages > Java

1 - About

Language - (Main|Application Entry point) in Java is called a Main class.

The (Main|Start) class is a class that:

You may have several main class in a jar

Advertising

3 - How to execute a main class ?

3.1 - Java

You can start the java application by:

java -classPath myJar.jar  com.package.myMainClass arg1 arg2

3.2 - Runnable Jar and Manifest file

If in the jar, you have a manifest file that contains the Main-Class attribute, the jar becomes a runnable jar

manifest
Manifest-version: 1.0
Main-Class: HelloWorld

and can be executed like that:

java -jar myStartableJar.jar

3.3 - Maven

Maven will take care of the classpath

mvn package exec:java -Dexec.mainClass=package.Class
Advertising

3.4 - Eclipse