linux java可执行程序_Linux上java程序打包为#可执行程序(Create an executable program on Linux)...

In this tutorial, we come to the jar package to do a demonstration.

create a jar file of your java class

.jar format file is one kind of executable files on linux platform like .exe file on windows platform.

to start with, we need a java file which contains our project.

to be more easy to grasp, i write an easy hello world program here

public class Pro{

public static void main(String[] args){

System.out.println("hello world!");

}

}

so we finish the first and basic mission, and save this file with Pro.java. and then let us see the mysteries together next.

okey, let’s compile it first. hahah… i almost forget this significant processing.

javac -d . Pro.java

we just know it has complied our java program, but we don’t what is added to its root dictionary. then, we use the command below to search the file names.

ls

787a9eaee29dcb36703e15f462f3d96c.png

we can easily find a new file named Pro.class, so it’s nice and we go on.

we should create a manifest attribute into jar

vi ManiFest.MF

to enter these content

Main-Class: Pro

in the end, it’s time to pack the jar

jar cvmf ManiFest.MF Pro.jar Pro.class

c494e63fb54fc33893dfa3de869b80bc.png

it’s the ideal figure of result to see.

finally, we can run the jar package as an “.exe” program like on windows.

java -jar Pro.jar

1100184f92cee9b4ce235c8bab338f27.png

so we can write our own PC programs to execute and we can share them to others who lacks the knowledge about java, and they can use these program by just one command or you can create a easy bash to let them use more conveniently.

if it help you a little please give me a like, thank you very much!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值