Error Making Jar Build

Asked

Viewed 606 times

8

I’m trying to do the build of my first JAR using the Intellij and Maven to manage 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 folder META-INF, but it didn’t help either.

Editing: I made a test and managed to run my JAR, as long as 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>
  • What is the error you give when running mvn clean install ?

  • There is no mistake

  • Which IDE you are using?

  • I am using Intellij

  • could edit your question and show your pom.xml?

  • @Math is in hand!

  • Are you using Swing? How did you get your jar to run when you didn’t indicate what the main class is in pom.xml?

  • Yes I’m using swing. Well, then I don’t know, it spun, maybe because it’s appearing in the Manifest.

  • @Strokes if not ask too much could include MANIFEST.MF in the body of your question?

Show 4 more comments

1 answer

3


Good,

I think (since I don’t have access to your Manifest file) that it might be one of the following, because in fact what the error indicates is that there is a conflict in the signature file.

Invalid signature file digest for Manifest main attributes

Solutions:

  1. You’re including a jar with a different signature than the jar you’re creating and as such you’re making a conflict. For this the solution is to add it in the Manifest with external dependency that already happened to me but it was working with Eclipse, in principle should be able to do this with GUI if it is the Intellij options or if you do not even have to modify the Maven Manifest manually;
  2. The second hypothesis is also a conflict in the current signature with the one you want to generate where the solution would be to remove the META-INF folder in all the jars you are using, re-generate Manifest or keep seeing if the jars are added there (if you do not add them again) and re-sign all jars with your signature, with the exception of external bookshops where you should apply solution 1;
  3. The third possibility, although it is less likely is that in the Intellij options you have to create Jar with signature while at the same time adding no signature to Jar (in Manifest).

Completion:

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

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

References:

Edition 29-04-14:

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

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

So you have to add this to the ones that should be inside in 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 edition:

  • This is very strange, because although I have a manifest the only information I have in it are: Manifest-Version: 1.0&#xA;Main-Class: Executor I have no signature added.

  • 1

    It must have to do with dependencies then. I bet on solution 1. Edition: I saw that this was the solution that worked. What happened was that the jar I was creating had no signature and by including some jar/bookstore that has a signature, there will be conflict, so you have to add them as an external dependency to your project.

  • So these libraries I’m using can’t be extracted inside my JAR?

  • 1

    In general it is only possible if they are from the same author(s), having the same key. However, I’ve heard of a plugin for Maven that allows you to assemble an entire project in one jar (there are also other formats) which is called maven-assembly-plugin.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.