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

Linux上java程序打包为#可执行程序(Create an executable program on Linux)_第1张图片
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

在这里插入图片描述
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

在这里插入图片描述
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!

你可能感兴趣的:(java)