Java - 导出包含引用库的Runnable JAR(错误:Manifest主要属性的无效签名文件摘要)

时间:2015-03-11 20:57:29

标签: java eclipse jar manifest executable-jar

我看了很多,但我找不到能帮助我的答案。我正在尝试导出Runnable JAR,但我的应用程序取决于我在Eclipse的Referenced Libraries文件夹中的三个JAR。我已经尝试了Eclipse提供的所有三个选项,包括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

我想要包含哪三个JAR。有任何想法吗?提前谢谢!

1 个答案:

答案 0 :(得分:0)

On First Glance ...您当前的Manifest文件必须进行修改,尤其是 从以下开始替换最后几行

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
 一个CRLF ...

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

在JAR导出期间,选择"打包所需的库"

确保在导出期间提及新保存的清单。

现在将引用的库附加到新的jar文件中(即拖动引用jar文件并在yourjarfile上删除)

签署你的jar文件

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

它对我有用...希望它适合你!

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