Error making Jar Build

7

I'm trying to build my first JAR using IntelliJ and Maven to manage the dependencies. I created the artifact and executed build , but when I run the program I get the following exception :

Exception in thread "main" java.lang.SecurityException: Invalid signature file d
igest 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.JarIndex.getJarIndex(Unknown Source)
        at sun.misc.URLClassPath$JarLoader$1.run(Unknown Source)
        at sun.misc.URLClassPath$JarLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.misc.URLClassPath$JarLoader.ensureOpen(Unknown Source)
        at sun.misc.URLClassPath$JarLoader.<init>(Unknown Source)
        at sun.misc.URLClassPath$3.run(Unknown Source)
        at sun.misc.URLClassPath$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.misc.URLClassPath.getLoader(Unknown Source)
        at sun.misc.URLClassPath.getLoader(Unknown Source)
        at sun.misc.URLClassPath.getResource(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)

I tried to delete the META-INF folder, but it did not work either.

Editing: I ran a test and was able to run my JAR, telling you that the libraries are not extracted inside it, but outside the JAR.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>IRMaven</artifactId>
    <version>1.0-SNAPSHOT</version>
        <dependencies>
            <dependency>
                <groupId>org.apache.tika</groupId>
                <artifactId>tika-app</artifactId>
                <version>1.5</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
            <dependency>
                <groupId>org.apache.lucene</groupId>
                <artifactId>lucene-core</artifactId>
                <version>4.7.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.lucene</groupId>
                <artifactId>lucene-analyzers-common</artifactId>
                <version>4.7.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.lucene</groupId>
                <artifactId>lucene-queryparser</artifactId>
                <version>4.7.0</version>
            </dependency>
        </dependencies>
</project>
    
asked by anonymous 17.04.2014 / 19:48

1 answer

3

Good,

I think (since I do not have access to your Manifest file) which can be one of the following situations, because in fact what the error indicates is that there is a conflict in the signatures file.

Invalid signature file digest for Manifest main attributes

Solutions:

  • You are adding a jar with a signature other than the jar you are creating and as such is conflicting. For this the solution is to add it in Manifest with external dependency that already happened to me but was working with Eclipse, in principle should be able to do this with GUI if it is IntelliJ options or if you do not have to modify even Manifest manually Maven;
  • The second hypothesis is also a conflict in the current signature with which you want to generate in which the solution would be to remove the META-INF folder on all the jars you are using, to generate the Manifest again or if it has remained to see if the jars are added (if you do not add them again) and re-sign all jars with your signature, with the exception of external bookstores where you should apply solution 1;
  • The third possibility, even though it is the least likely is that in the IntelliJ options you have to create the signed Jar while at the same time you are not adding any signature to Jar (in Manifest).
  • Conclusion:

    What is causing the problem is the security option of the Jar that are the signatures, this to protect the plagiarism programmer, as such all the Jars of a project must have the same signature or the ones that are not programmer should be added as an external bookstore.

    What I suggest is that you try to apply the given solutions and also read the references added below and if this does not solve your problem you will have to add more details about your project to your question, such as the Manifest file, libraries added (external or not), how you applied the signatures, etc.

    References:

    Issue 29-04-14:

    After the question, in the comments, it is possible to add all dependencies in files in a I can only respond that Maven has a plugin that allows to do this. What the plugin does is to encapsulate all dependencies in a jar file only (as if you were creating a zip). Note: Some programs can "unpack" this jar, so if you do not want anyone to see the dependencies for security reasons you should study the plugin security options well. As I have never used it myself, I do not feel 100% comfortable with this plugin and so I did not add it to the answer right away.

    This solution consists of adding to the pom.xml plugin maven-assembly-plugin indicating that it is a jar-with-dependencies .

    So you have to add this to the ones that should be inside the pom.xml:

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    

    In your particular pom.xml the following should work:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://maven.apache.org/POM/4.0.0"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>groupId</groupId>
        <artifactId>IRMaven</artifactId>
        <version>1.0-SNAPSHOT</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.tika</groupId>
                    <artifactId>tika-app</artifactId>
                    <version>1.5</version>
                </dependency>
                <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>1.2.17</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.lucene</groupId>
                    <artifactId>lucene-core</artifactId>
                    <version>4.7.0</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.lucene</groupId>
                    <artifactId>lucene-analyzers-common</artifactId>
                    <version>4.7.0</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.lucene</groupId>
                    <artifactId>lucene-queryparser</artifactId>
                    <version>4.7.0</version>
                </dependency>
            </dependencies>
    
            <!-- Inicio: As alterações que efectuei -->
            <build>
                <plugins>
                     <plugin>
                          <artifactId>maven-assembly-plugin</artifactId>
                          <executions>
                               <execution>
                                    <phase>package</phase>
                                    <goals>
                                         <goal>single</goal>
                                    </goals>
                               </execution>
                          </executions>
                          <configuration>
                               <descriptorRefs>
                                    <descriptorRef>jar-with-dependencies</descriptorRef>
                               </descriptorRefs>
                          </configuration>
                     </plugin>
                </plugins>
            </build>
            <!-- Fim: As alterações que efectuei -->
    </project>
    

    I hope this is the result you want, I'm waiting for feedback.

    References used in this issue:

    24.04.2014 / 02:25