linux环境下java程序打包成简单的hello world输出jar包示例
本文实例讲述了linux环境下java程序打包成简单的hello world输出jar包。分享给大家供大家参考,具体如下:
1.Linux 系统中必须先安装java,可以通过 java -version 查看是否安装;
[root@localhost ~]# java -version java version "1.8.0_11" Java(TM) SE Runtime Environment (build 1.8.0_11-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
可以查看到java版本号,说明已安装,未安装的自行安装java即可。
2.建立目录helloworld,在目录下建立helloworld.java文件,并写入内容
[root@localhost ~]# mkdir helloworld [root@localhost ~]# cd helloworld/ [root@localhost helloworld]# vi helloworld.java
helloworld.java内容如下:
public class helloworld { public static void main(String[] args) { System.out.println("Hello World!!"); } }
3.把helloworld.java 打包成可执行的jar
[root@localhost helloworld]# javac helloworld.java [root@localhost helloworld]# ls helloworld.class helloworld.java [root@localhost helloworld]# echo Main-class: helloworld > manifest.txt [root@localhost helloworld]# jar cvfm hello.jar manifest.txt helloworld.class added manifest adding: helloworld.class(in = 427) (out= 291)(deflated 31%)
4.运行hello.jar文件
至此,一个简单的jar包制作完成。
本文来自博客园,作者:别摸我的马甲线,转载请注明原文链接:https://www.cnblogs.com/a-wyw/p/16326099.html