博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Setting an Application's Entry Point
阅读量:4120 次
发布时间:2019-05-25

本文共 2267 字,大约阅读时间需要 7 分钟。

If you have an application bundled in a JAR file, you need some way to indicate which class within the JAR file is your application's entry point. You provide this information with the
Main-Class header in the manifest, which has the general form:
Main-Class: classname
The value
classname is the name of the class that is your application's entry point.

Recall that the entry point is a class having a method with signature public static void main(String[] args).

After you have set the Main-Class header in the manifest, you then run the JAR file using the following form of the java command:

java -jar JAR-name
The
main method of the class specified in the
Main-Class header is executed.

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

转载地址:http://ywipi.baihongyu.com/

你可能感兴趣的文章
IaaS, PaaS和SaaS 区别
查看>>
2012年华为还将发布78款园区交换机,15款AR路由器,18款WLAN产品,7款数据中心交换
查看>>
数据中心融合下的SAN通信
查看>>
云计算数据中心网络的关键技术
查看>>
Wiki - OpenFlow
查看>>
Nginx ngx_http_referer_module模块根据referer屏蔽或禁止访问
查看>>
Nginx缓存的两种方式
查看>>
Nginx浏览器缓存设置
查看>>
Nginx禁用缓存、禁止客户端保存文件
查看>>
入口是BAT的,但归根结底是属于社交的
查看>>
漫威十年,好莱坞的转型焦虑
查看>>
办公室的“批发转零售”
查看>>
写在“二更食堂”被关停之后
查看>>
无人驾驶引发车祸,背锅的到底是人还是车?
查看>>
谷歌9年投了323家公司,大公司做投资就是没梦想吗?
查看>>
老师给我推荐的经典管理书籍
查看>>
【解决方案】qq企业邮箱用outlook能发邮件不能收邮件,错误syntax error
查看>>
【解决方案】Vmware安装时出现的"already installed"错误
查看>>
【解决方案】windows win7 双击图片,不能通过照片查看器打开,有错误 “模块shimgvw.dll已加载,但找不到入口点DllRegisterServer ”
查看>>
最全的Windows7 服务优化、详解。
查看>>