How to Run a JAR file from Command Prompt - Windows as well as UNIX

So yous got a JAR file which contains your favorite Java game in addition to yous are wondering how to run Java plan from JAR  file? Or yous may move but trying your paw afterwards running Java plan from the dominance prompt in addition to Eclipse IDE. Anyway, it's skillful to know How to execute Java plan from JAR file, equally JAR file is a nigh pop way of transportation Java programs. JAR file unremarkably contains all origin in addition to resources inward the shape of course of teaching files, images, audio files etc. In lodge to run Java plan from JAR file, it must move an executable JAR file i.e. it manifest file within META-INF folder must incorporate a Main-class entry similar Main-Class: Hello, which specify the advert of Java course of teaching which contains measure main method inward Java. Without Main-class entry, yous tin non run a JAR file inward Java in addition to if yous movement to run such jolt file using jar dominance yous volition larn the mistake "Failed to charge Main-Class manifest attribute from HelloWorld.jar". If yous are non really much familiar amongst JAR file in addition to don't know How to practise an executable JAR, See this mensuration yesteryear mensuration tutorial on How to practise executable JAR inward Java. In this tutorial, nosotros volition exclusively focus on running Java plan from an executable JAR file.


Running Java plan from JAR file inward Java

main method equally an entry point. When nosotros run this JAR file using JAR command, JVM volition telephone yell upward this primary method which is specified inward its manifest file equally shown below:

Manifest-version: 1.0
Main-Class: Hello

By the way, don't forget to set PATH and  Classpath inward Java earlier running Java program. If classpath is specified inward the manifest file hence that volition move used yesteryear JVM in addition to it volition ignore CLASSPATH environs variable, If yous are non familiar amongst these details hence run across How classpath plant inward Java, must read for whatsoever beginner inward Java.


Once yous are certain that Java is installed inward your machine, path in addition to classpath are proper, precisely execute the next dominance in addition to it volition run your Java plan from the JAR file itself:

$ coffee -jar Hello.jar


If yous run across the mistake "no primary manifest attribute, inward Test.jar" it way your JAR file is non a runnable JAR file i.e. it's manifest file doesn't incorporate Main-Class attribute.

$ coffee -jar Test.jar
no primary manifest attribute, inward Test.jar

In my representative MANIFEST.MF file just contains 1 line:

Manifest-Version: 1.0

Once  I added the Main-Class attribute it run precisely fine equally shown below:

$ coffee -jar Test.jar
before swapping x: 3
before swapping y: 3
after swapping x: 3
after swapping y: 3

Here are squeamish slides amongst all steps required to run a JAR file from dominance prompt inward Windows 8 in addition to UNIX:

 So yous got a JAR file which contains your favorite Java game in addition to yous are wondering how to How to Run a JAR file from Command Prompt - Windows in addition to UNIX


If yous appear upward whatsoever termination related to Java, classpath in addition to path piece running your Java plan from JAR file, delight post service here. If yous don't know how to practise executable JAR file hence run across this tutorial. That tutorial gives yous mensuration yesteryear mensuration direct to making an executable JAR using Eclipse IDE. 


Other Java programming tutorial yous may honour useful

Subscribe to receive free email updates:

0 Response to "How to Run a JAR file from Command Prompt - Windows as well as UNIX"

Posting Komentar