验证7zjar包的版本可用性操作手册

相关文件:

1、测试程序上传

将目录 jar包测试\程序 下的text文件夹上传服务器/root目录下

2、jar包版本上传

打开目录 jar包测试\jar包 ,可以看到jar包的各种版本:

此处的jar包需要单独一个个进行测试上传,下面以文件sevenzipjbinding-16.02-2.01-AllLinux中的jar包上传测试为例。
打开文件sevenzipjbinding-16.02-2.01-AllLinux,将会看到两个jar包:

将此处两个jar包传输到服务器/root/test/lib目录下

3、测试程序运行

进入程序所在目录

1
cd /root/test/src/zip_7/

通过javac将.java编译为.class文件;

测试程序中包括两个java程序,其编译命令如下:

程序:SevenZipJBindingInitCheck.java

1
javac -classpath "/root/test/lib/*" SevenZipJBindingInitCheck.java

程序:PrintCountOfItems.java

1
javac -classpath "/root/test/lib/*" PrintCountOfItems.java

通过Java执行.class文件

程序:SevenZipJBindingInitCheck.java

1
java -cp $classpath:"/root/test/lib/*":./ SevenZipJBindingInitCheck
正确现象

1
7-Zip-JBinding library was initialized
错误现象:报错有很多种,可对其进行记录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
OpenJDK 64-Bit Server VM warning: You have loaded library /tmp/SevenZipJBinding-6OrbBDKGBkCL/lib7-Zip-JBinding.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
net.sf.sevenzipjbinding.SevenZipNativeInitializationException: 7-Zip-JBinding initialization failed: Error loading native library: '/tmp/SevenZipJBinding-6OrbBDKGBkCL/lib7-Zip-JBinding.so'
at net.sf.sevenzipjbinding.SevenZip.loadNativeLibraries(SevenZip.java:650)
at net.sf.sevenzipjbinding.SevenZip.initSevenZipFromPlatformJARIntern(SevenZip.java:456)
at net.sf.sevenzipjbinding.SevenZip.initSevenZipFromPlatformJAR(SevenZip.java:340)
at SevenZipJBindingInitCheck.main(SevenZipJBindingInitCheck.java:7)
Caused by: java.lang.UnsatisfiedLinkError: /tmp/SevenZipJBinding-6OrbBDKGBkCL/lib7-Zip-JBinding.so: /tmp/SevenZipJBinding-6OrbBDKGBkCL/lib7-Zip-JBinding.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1946)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1828)
at java.lang.Runtime.load0(Runtime.java:810)
at java.lang.System.load(System.java:1088)
at net.sf.sevenzipjbinding.SevenZip.loadNativeLibraries(SevenZip.java:648)

程序:PrintCountOfItems.java

1
java -cp $classpath:"/root/test/lib/*":./ PrintCountOfItems my-test-archive.zip
正确现象

1
Count of items in archive: 7
错误现象:报错有很多种,可对其进行记录

1
2
3
OpenJDK 64-Bit Server VM warning: You have loaded library /tmp/SevenZipJBinding-6OrbBDKGBkCL/lib7-Zip-JBinding.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Error occurs: java.lang.RuntimeException: SevenZipJBinding couldn't be initialized automaticly using initialization from platform depended JAR and the default temporary directory. Please, make sure the correct 'sevenzipjbinding-<Platform>.jar' file is on the class path or consider initializing SevenZipJBinding manualy using one of the offered initialization methods: 'net.sf.sevenzipjbinding.SevenZip.init*()'

4、总结

将目录: jar包测试\jar包 下的所有文件都执行按照2、3的步骤执行一遍:
如果可以执行出现正确现象,请记录jar包的版本已经其文件名,如:sevenzipjbinding-16.02-2.01-AllLinux
如执行报错,请记录报错信息。

程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class PrintCountOfItems {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Usage: java PrintCountOfItems <archive-name>");
return;
}
String archiveFilename = args[0];

RandomAccessFile randomAccessFile = null;
IInArchive inArchive = null;
try {
randomAccessFile = new RandomAccessFile(archiveFilename, "r");
inArchive = SevenZip.openInArchive(null, // autodetect archive type
new RandomAccessFileInStream(randomAccessFile));

System.out.println("Count of items in archive: "
+ inArchive.getNumberOfItems());

} catch (Exception e) {
System.err.println("Error occurs: " + e);
} finally {
if (inArchive != null) {
try {
inArchive.close();
} catch (SevenZipException e) {
System.err.println("Error closing archive: " + e);
}
}
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (IOException e) {
System.err.println("Error closing file: " + e);
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
public class SevenZipJBindingInitCheck {
public static void main(String[] args) {
try {
SevenZip.initSevenZipFromPlatformJAR();
System.out.println("7-Zip-JBinding library was initialized");
} catch (SevenZipNativeInitializationException e) {
e.printStackTrace();
}
}
}

验证7zjar包的版本可用性操作手册
http://yuanql.top/2022/11/16/00_项目经历/信创项目/专用系统下压缩软件验证/验证7zjar包的版本可用性操作手册/
作者
Qingli Yuan
发布于
2022年11月16日
许可协议