Low Orbit Flux Logo 2 F

Java How to Execute a Jar File

If you are looking for more information you might want to take a look at the following Java How to Create an Executable Jar File.

This will work if the main class was specified in the manifest.

You can run a jar file like this. Note that the main class will need to have been specified in the manifest when the jar was created.

java -jar HelloWorld.jar

Run a Non-Executable JAR with Arguments

We can also just run the main class directly if we specify that the jar should be on the class path using the “-cp” flags. This should work even if we didn’t specify the main class in the manifest.

java -cp HelloWorld.jar:com/test/HelloWorld com.test.HelloWorld.HelloWorld

You should also be able to pass parameters to the class that you run if it supports them.