0
votes

I have looked around quite a bit but I haven't found an answer that helps me. I am trying to export a Runnable JAR but my application is depending on three JARs that I have in my Referenced Libraries folder in Eclipse. I have tried all three options that Eclipse offers for including JARs ("Extract required libraries into generated JAR", "Package required libraries into generated JAR", and "Copy required libraries into a sub-folder next to the generated JAR") but when I run my jar like this:

java -jar test2.jar

I get the same error:

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)

In my lib/META-INF/MANIFEST.MF I have:

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=

about 700 lines that look just like these and then at the end I have

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

Which are the three JARs I want to include. Any ideas? Thanks in advance!

1

1 Answers

0
votes

On First Glance... your current Manifest file must be modified, especially Replace Last Couple of lines starting from

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

Check that All the Line Breaks/New Line/Line Endings are be in Windows CRLF Format.

During JAR Export, select "Package required libraries"

Make sure to Mention Newly saved Manifest during export.

Now Append your referenced libraries into your new jar file (i.e. Drag reference jar files and Drop on yourjarfile)

Sign your jarfile

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

it worked for me...Hope it works for you!

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