views:

2782

answers:

4

My java program is packaged in a jar file and makes use of an external jar library, bouncy castle. My code compiles fine, but running the jar leads to the following error:

Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

I've googled for over an hour searching for an explanation and found very little of value. If anyone has seen this error before and could offer some help, I would be obliged.

+1  A: 

Link

The solution listed here might provide a pointer. Bottom line :

It's probably best to keep the official jar as is and just add it as a dependency in the manifest file for your application jar file.

Nrj
How would I reflect this in the manifest file? I've never edited one before. I'm using Xcode, and the common convention is to put external jar libraries in the myproject/lib directory for inclusion, which is what I am doing.
oskar
Try Class-Path: LIB_PACKAGE/ in the manifest file.
Nrj
+1  A: 

Compare the folder META-INF in new jar with old jar (before you added new libraries). It is possibility that there will be new files. If yes, you can remove them. It should helps. Regards, 999michal

999michal
A: 

I had a similar problem. The reason was that I was compiling using a JDK with a different JRE than the default one in my Windows box.

Using the correct java.exe solved my problem.

Jus12
+1  A: 

Assuming you build your jar file with ant, you can just instruct ant to leave out the META-INF dir. This is a simplified version of my ant target:

<jar destfile="app.jar" basedir="${classes.dir}">
    <zipfileset excludes="META-INF/**/*" src="${lib.dir}/bcprov-jdk16-145.jar"></zipfileset>
    <manifest>
        <attribute name="Main-Class" value="app.Main"/>
    </manifest>
</jar>
Kim