java beginner. Until you create a jar file with java and execute it.
① Create an appropriate directory ② Create an appropriate java file ③ Create JAR file ④ Play with the manifest file ⑤ Execution
~/sample/
Working directory: ~ / sample / Sample.java
package sample;
public class Sample{
public static void main(String[]args){
System.out.println("I was able to execute");
}
}
Try compiling and running it once. Working directory: ~
> javac sample/Sample.java
> java sample.Sample
I was able to execute
Working directory: ~
>jar -cvf Sample.jar sample/
Manifest added
sample/Is being added(Enter=0)(Out=0)(0%Stored)
sample/Sample.class is being added(Enter=428)(Out=305)(28%Shrinked)
sample/Sample.Java is being added(Enter=137)(Out=120)(12%Shrinked)
** Check the contents of the JAR file **
> jar -tvf Sample.jar
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
0 Sat Mar 14 12:19:02 JST 2020 META-INF/
66 Sat Mar 14 12:19:02 JST 2020 META-INF/MANIFEST.MF
0 Sat Mar 14 12:15:34 JST 2020 sample/
428 Sat Mar 14 12:15:34 JST 2020 sample/Sample.class
137 Sat Mar 14 12:09:48 JST 2020 sample/Sample.java
Working directory: ~ Contents of META-INF / MANIFEST.MF
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 13.0.2 (Oracle Corporation)
** Creating a manifest file **
Sample.mani
Main-Class: sample.Sample
** Addition of main manifest attribute **
>jar -uvfm Sample.jar Sample.mani
Manifest updated
Contents of META-INF / MANIFEST.MF after execution
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 13.0.2 (Oracle Corporation)
Main-Class: sample.Sample
I wrote Main-Class directly to MANIFEST.MF, but I couldn't execute it.
Working directory: ~
> java -jar Sample.jar
I was able to execute
** Other execution methods **
> java -cp Sample.jar sample.Sample
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
I was able to execute
Recommended Posts