`
fengpy2009
  • 浏览: 249701 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

JAR Files as Applications

阅读更多

http://docs.oracle.com/javase/tutorial/deployment/jar/run.html

 

JAR Files as Applications

You can run JAR-packaged applications with the Java interpreter. The basic command is:

java -jar jar-file


The -jar flag tells the interpreter that the application is packaged in the JAR file format. You can only specify one JAR file, which must contain all the application-specific code.

Before you execute this command make sure the runtime environment has an information of which class within the JAR file is the application's entry point.

To indicate which class is the application's entry point, you must add a Main-Class header to the JAR file's manifest. The header takes the form:

Main-Class: classname


The header's value, classname , is the name of the class that's the application's entry point.

For more information, see the Setting an Application's Entry Point section.

When the Main-Class is set in the manifest file, you can run the application from the command line:

java -jar app.jar

To run the application from jar file that is in other directory, we need to specify the path of that directory as below: java -jar path/app.jar

where path is the directory path at which this app.jar resides.

 

 

An Example

We want to execute the main method in the class MyClass in the package MyPackage when we run the JAR file.

We first create a text file named Manifest.txt with the following contents:

Main-Class: MyPackage.MyClass

Warning:  

The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.


We then create a JAR file named MyJar.jar by entering the following command:

jar cfm MyJar.jar Manifest.txt MyPackage/*.class

This creates the JAR file with a manifest with the following contents:

Manifest-Version: 1.0
Created-By: 1.6.0 (Sun Microsystems Inc.)
Main-Class: MyPackage.MyClass

When you run the JAR file with the following command, the main method of MyClass executes:

java -jar MyJar.jar

Setting an Entry Point with the JAR Tool

The 'e' flag (for 'entrypoint'), introduced in JDK 6, creates or overrides the manifest's Main-Class attribute. It can be used while creating or updating a jar file. Use it to specify the application entry point without editing or creating the manifest file.
For example, this command creates app.jar where the Main-Class attribute value in the manifest is set to MyApp :

jar cfe app.jar MyApp MyApp.class

You can directly invoke this application by running the following command:

java -jar app.jar

If the entrypoint class name is in a package it may use a '.' (dot) character as the delimiter. For example, if Main.class is in a package called foo the entry point can be specified in the following ways:

jar cfe Main.jar foo.Main foo/Main.class
分享到:
评论

相关推荐

    restful restful所需要的jar包

    restful restful所需要的jar包 ========================================= Restlet, a RESTful Web framework for Java ========================================= http://www.restlet.org -------------------...

    UE(官方下载)

    This power tip provides an explanation as well as some tips to get the most out of temp files. Backup and Restore Settings One of the staples of UltraEdit (and UEStudio) is its highly configurable ...

    tomcat-5.5.23

    logs - Log and output files <br>* shared - For classes and resources that must be shared across all web applications <br>* webapps - Automatically loaded web applications <br>* work - ...

    Learning Apache Karaf

    deploying and provisioning applications is just as important to the successful implementation of a stable and scalable architecture. You will discover how to monitor runtime environments using remote...

    tomcat-8_API

    or by placing them in JAR files in the "lib" directory. To override the XML parser implementation or interfaces, use the endorsed mechanism of the JVM. The default configuration defines JARs located ...

    Android代码-capsule

    A capsule is a single executable JAR that contains everything your application needs to run either in the form of embedded files or as declarative metadata. It can contain your JAR artifacts, your ...

    tomcat-7_API_帮助文档

    or by placing them in JAR files in the "lib" directory. To override the XML parser implementation or interfaces, use the endorsed mechanism of the JVM. The default configuration defines JARs located ...

    apktool documentation

    If you were to simply unzip an apk like so, you would be left with files such as classes.dex and resources.arsc. $ unzip testapp.apk Archive: testapp.apk inflating: AndroidManifest.xml inflating: ...

    spring-boot-reference.pdf

    11.5. Creating an Executable Jar 12. What to Read Next III. Using Spring Boot 13. Build Systems 13.1. Dependency Management 13.2. Maven 13.2.1. Inheriting the Starter Parent 13.2.2. Using Spring Boot ...

    jdk-9.0.1_doc-all 最新版

    Defines tools for manipulating Java Archive (JAR) files, including the jar and jarsigner tools. jdk.javadoc Defines the implementation of the system documentation tool and its command line equivalent...

    Java APIs, Extensions and Libraries-Apress(2018).pdf

    Java applications were packaged in JARs before JDK9. JDK9 has added several enhancements to the JAR format. JDK9 added a new type of JAR called the multi-release JAR, which can package code for a ...

    jboss in action

    instead, we provide diagrams showing the contents of theresulting packages (JAR, WAR, EAR, and so on). We assume that you can use whatever tools you’re familiar with to compile and package the ...

    Java2核心技术卷I+卷2:基础知识(第8版) 代码

    JAR Files 494 Java Web Start 501 Applets 516 Storage of Application Preferences 539 Chapter 11: Exceptions, Logging, Assertions, and Debugging 551 Dealing with Errors 552 Catching Exceptions ...

    java.核心技术.第八版 卷1

    JAR Files 494 Java Web Start 501 Applets 516 Storage of Application Preferences 539 Chapter 11: Exceptions, Logging, Assertions, and Debugging 551 Dealing with Errors 552 Catching Exceptions ...

    java7帮助文档

    JDK 7 is a superset of JRE 7, and contains everything that is in JRE 7, plus tools such as the compilers and debuggers necessary for developing applets and applications. JRE 7 provides the libraries, ...

    Java邮件开发Fundamentals of the JavaMail API

    this is the purview of applications such as sendmail and other Mail Transfer Agent (MTA) type programs. MUA-type programs let users read and write e-mail, whereas MUAs rely on MTAs to handle the ...

    JavaSE-6.0-英文手册(2008/11/30_FullUpdate)

    Java Archive (JAR) Files Logging Preferences Regular Expressions Zip Files Other packages Math I/O Object Serialization Networking Endorsed Standards Override Mechanism ...

    新版Android开发教程.rar

    The sections below describe the system and software requirements for developing Android applications using the Android SDK tools included in Android 1.1 SDK, Release 1. Supported Supported Supported ...

Global site tag (gtag.js) - Google Analytics