当前位置: 首页 > 知识库问答 >
问题:

Java-导出包含引用库的可运行JAR(错误:清单主属性的签名文件摘要无效)

斜单鹗
2023-03-14

我找了很多地方,但我没有找到一个对我有帮助的答案。我试图导出一个可运行的JAR,但我的应用程序依赖于Eclipse中Referenced Libraries文件夹中的三个JAR。我尝试了Eclipse为包含jar提供的所有三个选项(“将所需库提取到生成的jar中”、“将所需库打包到生成的jar中”和“将所需库复制到生成的jar旁边的子文件夹中”),但当我运行jar时,如下所示:

java -jar test2.jar

我得到了同样的错误:

Error: A JNI error has occurred, please check your installation and try again 
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest 
for Manifest main attributes 
    at sun.security.util.SignatureFileVerifier.processImpl(Unknown Source)
    at sun.security.util.SignatureFileVerifier.process(Unknown Source)
    at java.util.jar.JarVerifier.processEntry(Unknown Source)
    at java.util.jar.JarVerifier.update(Unknown Source)
    at java.util.jar.JarFile.initializeVerifier(Unknown Source)
    at java.util.jar.JarFile.getInputStream(Unknown Source)
    at sun.misc.URLClassPath$JarLoader$2.getInputStream(Unknown Source)
    at sun.misc.Resource.cachedInputStream(Unknown Source)
    at sun.misc.Resource.getByteBuffer(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

在我的lib/meta-inf/manifest.mf中,我有:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 16.2-b04 (Sun Microsystems Inc.)

Name: com/microsoft/sqlserver/jdbc/SQLServerException.class
SHA1-Digest: 9TYxLKZ+paXj6p79UrUIAyNKUxk=

Name: com/microsoft/sqlserver/jdbc/JDBCType$UpdaterConversion.class
SHA1-Digest: SSNtCkMkIRF4cfive1V/Caz+BV4=

Name: com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData$MetaInfo
.class
SHA1-Digest: ce1nIUlFUVqA1YEj4HF1PVkUITM=

Name: com/microsoft/sqlserver/jdbc/SQLServerResultSet$FetchBuffer.clas
s
SHA1-Digest: H9S+pI7NZwXoVCL7a1dJz5sspI8=

Name: com/microsoft/sqlserver/jdbc/StreamPacket.class
SHA1-Digest: Z0bpYj+nDhx0nkRcIJjn65MwJC0=

Name: com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolDataSource.c
lass
SHA1-Digest: R49XXWhfB2G0I9MEsK/wdl83e9U=

大约700行,看起来就像这些,然后在最后我有

Class-Path: C:/Users/luis/workspace/jaf-1.1.1/activation.jar 
C:/Users/luis/workspace/javamail-1.4.7/mail.jar 
C:/Users/luis/workspace/sqljdbc_4.0/enu/sqljdbc4.jar

这是我要包括的三个罐子。有什么想法吗?提前道谢!

共有1个答案

曹臻
2023-03-14

乍一看...必须修改当前清单文件,特别是替换从

Class-Path: C:/Users/luis/workspace/jaf-1.1.1/activation.jar
C:/Users/luis/workspace/javamail-1.4.7/mail.jar
C:/Users/luis/workspace/sqljdbc_4.0/enu/sqljdbc4.jar

检查所有换行符/新行/行尾是否为Windows CRLF格式。

在JAR导出过程中,选择“Package required

确保在导出过程中提及新保存的清单。

现在,将引用的库追加到新的jar文件中(例如,拖动引用的jar文件并拖放到yourjarfile上)

签名您的jarfile

 jarsigner "yourjarfile" KeyName -tsa http://timestamp.digicert.com 

对我有用...希望对你有用!

请参阅http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jarsigner.html

 类似资料: