Sunday, November 24, 2019

How To Operate A Appall File From Ascendence Prompt - Windows Together With Unix

So yous got a JAR file which contains your favorite Java game together with yous are wondering how to run Java plan from JAR  file? Or yous may hold out only trying your manus later running Java plan from the ascendance prompt together with Eclipse IDE. Anyway, it's practiced to know How to execute Java plan from JAR file, every bit JAR file is a almost pop way of transportation Java programs. JAR file ordinarily contains all rootage together with resources inwards the shape of degree files, images, audio files etc. In lodge to run Java plan from JAR file, it must hold out 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 refer of Java degree which contains measure main method inwards Java. Without Main-class entry, yous tin ship away non run a JAR file inwards Java together with if yous attempt to run such offend file using jar ascendance yous volition instruct the fault "Failed to charge Main-Class manifest attribute from HelloWorld.jar". If yous are non really much familiar amongst JAR file together with don't know How to create an executable JAR, See this measurement past times measurement tutorial on How to create executable JAR inwards Java. In this tutorial, nosotros volition exclusively focus on running Java plan from an executable JAR file.


Running Java plan from JAR file inwards Java

 So yous got a JAR file which contains your favorite Java game together with yous are wondering how to How to Run a JAR file from Command Prompt - Windows together with UNIXmain method every bit an entry point. When nosotros run this JAR file using JAR command, JVM volition telephone telephone this primary method which is specified inwards its manifest file every bit shown below:

Manifest-version: 1.0
Main-Class: Hello

By the way, don't forget to set PATH and  Classpath inwards Java earlier running Java program. If classpath is specified inwards the manifest file together with therefore that volition hold out used past times JVM together with it volition ignore CLASSPATH environs variable, If yous are non familiar amongst these details together with therefore come across How classpath plant inwards Java, must read for whatsoever beginner inwards Java.



Once yous are certain that Java is installed inwards your machine, path together with classpath are proper, exactly execute the next ascendance together with it volition run your Java plan from the JAR file itself:

$ coffee -jar Hello.jar


If yous come across the fault "no primary manifest attribute, inwards Test.jar" it agency 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, inwards Test.jar

In my example MANIFEST.MF file just contains ane line:

Manifest-Version: 1.0

Once  I added the Main-Class attribute it run exactly fine every bit shown below:

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

Here are prissy slides amongst all steps required to run a JAR file from ascendance prompt inwards Windows 8 together with UNIX:

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


If yous expression upward whatsoever effect related to Java, classpath together with path spell running your Java plan from JAR file, delight post service here. If yous don't know how to create executable JAR file together with therefore come across this tutorial. That tutorial gives yous measurement past times measurement conduct to making an executable JAR using Eclipse IDE. 


Other Java programming tutorial yous may uncovering useful

No comments:

Post a Comment