Run jar file in command prompt

JavaJar

Java Problem Overview


How do we run a jar file in command prompt?

Java Solutions


Solution 1 - Java

Try this

java -jar <jar-file-name>.jar

Solution 2 - Java

If you dont have an entry point defined in your manifest invoking java -jar foo.jar will not work.

Use this command if you dont have a manifest or to run a different main class than the one specified in the manifest:

java -cp foo.jar full.package.name.ClassName

See also instructions on how to create a manifest with an entry point: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

Solution 3 - Java

java [any other JVM options you need to give it] -jar foo.jar

Solution 4 - Java

You can run a JAR file from the command line like this:

java -jar myJARFile.jar

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNiravView Question on Stackoverflow
Solution 1 - JavaBala RView Answer on Stackoverflow
Solution 2 - JavaLynchView Answer on Stackoverflow
Solution 3 - JavaQuantumMechanicView Answer on Stackoverflow
Solution 4 - JavaicktoofayView Answer on Stackoverflow