Article Directory
Understand the process of java packaging jar
Problems encountered
A Java face recognition library is called. The
recognition library relies on the so dynamic link library
and a third-party jar library.
In order to package the entire project into a jar file
that can be run directly, record the process
The first step is to compile the class file from the source code
For windows platform, the -encoding utf8 option
-d is added. It represents the directory structure of the generated class
-cp represents the third-party class dependency or it can be a jar file
so directly in the program to load according to the absolute path.
FaceEngineTest.java is the source code Entry file
javac -encoding utf8 -d . -cp C:\gitproj\javaSwing\lib\arcsoft-sdk-face-3.0.0.0.jar FaceEngineTest.java
Generate jar package according to class
Write the
manf file of the packaging task list for a
more detailed guide.
https://www.w3cschool.cn/java/java-io-jar-manifest.html
manf file content
Main-Class: FaceEngineTest
Class-Path: arcsoft-sdk-face-3.0.0.0.jar
jar packaging command
-c, --create create archive
-v, --verbose generate verbose output in standard output
-f, --file=FILE archive file name. When omitted, use stdin or stdout based on the operation,
-m, --manifest=FILE contains the manifest information in the specified manifest file
jar cvfm demo.jar manf .\FaceEngineTest.class
Use command
java -jar .\demo.jar
[com.arcsoft.face.Rect(116, 124 - 365, 373),1]
特征值大小:1032
[com.arcsoft.face.Rect(116, 124 - 365, 373),1]
特征值大小:1032
相似度:1.0
性别:0
help description
法: jar [OPTION...] [ [--release VERSION] [-C dir] files] ...
jar 创建类和资源的档案, 并且可以处理档案中的
单个类或资源或者从档案中还原单个类或资源。
示例:
# 创建包含两个类文件的名为 classes.jar 的档案:
jar --create --file classes.jar Foo.class Bar.class
# 使用现有的清单创建档案, 其中包含 foo/ 中的所有文件:
jar --create --file classes.jar --manifest mymanifest -C foo/ .
# 创建模块化 jar 档案, 其中模块描述符位于
# classes/module-info.class:
jar --create --file foo.jar --main-class com.foo.Main --module-version 1.0
-C foo/ classes resources
# 将现有的非模块化 jar 更新为模块化 jar:
jar --update --file foo.jar --main-class com.foo.Main --module-version 1.0
-C foo/ module-info.class
# 创建包含多个发行版的 jar, 并将一些文件放在 META-INF/versions/9 目录中:
jar --create --file mr.jar -C foo classes --release 9 -C foo9 classes