Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Jar in Console

Tags:

java

I am writing a java applicaiton that outputs strings via System.out and I just want to know how to run this application outside my IDE. I have an executable jar. What does one do to see this output in a console?

like image 380
Nick Avatar asked Oct 24 '09 21:10

Nick


People also ask

How do you run a JAR file?

To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar. We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …]

Can you run .jar files on Linux?

jar file from the Linux terminal. To do this, you must have java command line tool installed to launche a Java application, and the -jar flag to execute a program encapsulated in a JAR file. When this flag is used, the specified JAR file is the source of all user classes, and other class path settings are ignored.


2 Answers

Basically: java -jar app.jar

Sun's site has more info

like image 188
Malaxeur Avatar answered Oct 23 '22 19:10

Malaxeur


As others have suggested:

java -jar JarFIle.jar

Note this requires you to set the main class entry point

If you don't/can't set Main-Class then you would do:

java -cp JarFile.jar package.Classname 

Additionally if you associate jar file types with your JRE then double click should work too.

like image 26
Joel Avatar answered Oct 23 '22 21:10

Joel