`
fengpy2009
  • 浏览: 251381 次
  • 性别: 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 ...

    Efficient MIDP Programming

    JAR files (Java Archive files) contain compiled Java classes and associated metadata. Smaller JAR file sizes can improve application performance by reducing download times and minimizing memory usage....

    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: ...

    Jetty For Eclipse 插件快速安装.rar

    通常,它位于"Program Files"或"Applications"下,具体路径取决于你的操作系统。 - 进入Eclipse的安装目录,然后找到并打开"Plugins"文件夹。这个文件夹包含了Eclipse所有已安装和可用的插件。 - 将解压得到的三...

    glassfish和ant安装与配置

    - 将编译好的WAR文件放置于GlassFish的`domains/domain1/applications`目录下。 - 访问http://localhost:8080/网站名来查看应用是否部署成功。 #### 四、Ant安装与配置 1. **下载并安装Ant**: - 下载最新版本的...

    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...

    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 - ...

    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 ...

    ORACLE JDE安装指南

    - 将“C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib”下的“msbase.jar”、“mssqlserver.jar”、“msutil.jar”复制到“C:\E812\system\OC4J\j2ee\home\applib”目录。 - 这一步骤是为了支持...

    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 ...

Global site tag (gtag.js) - Google Analytics