4

My Maven shade plugin worked well until I started to use MsSQL JDBC

When I add MsSql to pom.xml and I want to run the app I get an 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

Any suggestion how can I resolve it? However, the Main class is empty just a simple main method is there.

 <build>
        <plugins>            

          <!-- Maven Shade Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <!-- Run shade goal on package phase -->
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <!-- add Main-Class to manifest file -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>mdb.Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>    

        </plugins>
 </build>

 <dependencies>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.2.2.jre7</version>
        </dependency>                 

 </dependencies>

</project>
user2287094
  • 267
  • 4
  • 13
  • oh, if I delete the *.RSA file from the .jar meta-inf then it works... but I don't think its a real solution... – user2287094 Oct 10 '18 at 14:46
  • 1
    That is the solution. The files in the jar are signed, and by shading, the signature becomes invalid. You should really consider whether you should shade at all. – Mark Rotteveel Oct 10 '18 at 15:05
  • 1
    Related, possibly duplicate: https://stackoverflow.com/questions/25779708/how-to-tell-the-maven-shade-plugin-to-preserve-signatures?rq=1 and https://stackoverflow.com/questions/34738653/maven-shade-plugin-does-not-exclude-the-manifest-signature-files?rq=1 – Mark Rotteveel Oct 10 '18 at 15:06
  • I see thanks. Its a signed jar. I really need to make a fat jar. And I have to use mssql. Can I use any other fat-jar-maker or other msSql driver, which works? – user2287094 Oct 10 '18 at 15:16
  • 2
    You should be able to configure maven shade to skip the signature file when shading, that should fix your problem. – Mark Rotteveel Oct 10 '18 at 15:19
  • Thank you! Works! – user2287094 Oct 10 '18 at 15:35

1 Answers1

8
<configuration>                                                                 
                            <filters>

                            <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>

                        </filters>                            
</configuration>
user2287094
  • 267
  • 4
  • 13