Home / Java Techs / Java / How to run JAR packaged applications

How to run JAR packaged applications

Print Friendly

A few questions can be questioned when someone wants to learn Java programming. For example, how is its independent on working environment? How can we create a standalone program? How to run a Java program? etc. This post will answer a question among those. Although you are an experienced Java programmer, I suspect this post could be one of the favourite items in your programming handbook.

In this post, I want to make everything clearer by classifying a Java program into some phenomena.

First of all, I want to denote some conventional technical things in order to make this post more manageable and readable.

The technical terms are used in this post

  • java: name of Java program
  • -cp : the option of Java program telling it run the jar file
  • -jar : the option of Java program telling it run the jar file
  • YourApp.jar : the jar file which you want to run with
  • com.itersdesktop.javatechs.MainApp : the Fully Qualified Domain Name (FQDN) of the main class (entry point program). Notes

A typical program written in pure Java programming language and compiled to a jar file can be generally run by executing the following command:

jar -jar YourApp.jar

But if you don’t have a manifest file in your jar, this command doesn’t work at all of the time. You will get an error telling no main manifest attribute, in YourApp.jar . If it is the case and you really want to run your program for whatever reasons, the following command can be helpful:

java -cp YourApp.jar com.itersdesktop.javatechs.MainApp
java -cp YourApp.jar YourClass

java -cp YourApp.jar YourClass

Otherwise, the following command allows to run
java -jar YourApp.jar com.itersdesktop.javatechs.MainApp

Here if you want to know how to create an executable jar file.


About Admin

programming all time and taking a bread for the lunch hahaha... When you are engaging your work, nobody can attract you doing another thing. Otherwise, should should move to other jobs or are not interested in your job enough.