[Java] [Microsoft] Things to be aware of when including the JDBC driver for SQL Server in one jar

First stage

Maven Shade Plugin That's convenient. You can start the program with a single jar file without writing a lengthy classpath.

It happened when I tried to put the JDBC driver of Microsoft SQL Server in such a jar file.

What i did

What happened

When I ran it, it failed with this 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 

People with the same problem → https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f5c69fee-8c68-4601-bfcb-376e21dfa809/sql-server-jdbc-javalangsecurityexception-invalid-signature-file- digest? forum = sqldataaccess

Cause

Is it because the signature is in sqljdbc4.jar? ↑ I don't understand at all.

solution

Do not include the signature file (?) Included in sqljdbc4.jar in the final jar.

pom.xml


(snip)
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
(snip)
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
(snip)

One by one

You have to understand how Java handles and executes jar files. .. ..

Recommended Posts

[Java] [Microsoft] Things to be aware of when including the JDBC driver for SQL Server in one jar
Things to be aware of when writing code in Java
Things to be aware of when writing Java
[Java] Things to be aware of when outputting FizzBuzz
Summarize the life cycle of Java objects to be aware of in Android development
Conditional branching of the result of SQL statement to search only one in Java
[Java] [SQL Server] Connect to local SQL Server 2017 using JDBC for SQL Server
Things to be aware of when using devise's lockable
[Java Silver] Things to be aware of regarding switch statements
How to increment the value of Map in one line in Java
Is it easy for the user to use when implementing general-purpose functions? Let's be aware of
How to find the total number of pages when paging in Java
Sample code to get the values of major SQL types in Java + MySQL 8.0
When the server fails to start in Eclipse
Things to watch out for in Java equals
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
Summary of how to use the proxy set in IE when connecting with Java
[Java] Get the file in the jar regardless of the environment
I want to be aware of the contents of variables!
"The Language Support for Java server crashed 5 times in the last 3 minutes. The server will not be restarted."
In SpringBoot 2.3.0 or later, the placeholder used for the value of @PropertySource fails to be resolved.
Sample code to get the values of major SQL types in Java + Oracle Database 12c
How to derive the last day of the month in Java
[Rails] Where to be careful in the description of validation
Be sure to compare the result of Java compareTo with 0
Reintroduction to Java for Humanities 0: Understanding the Act of Programming
Fix the file name of war to the one set in Maven
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
Determine if the strings to be compared are the same in Java
How to solve the unknown error when using slf4j in Java
How to check for the contents of a java fixed-length string
Investigation method when the CPU of the server running java is heavy
How to get the length of an audio file in java
[Java] Equivalence comparison where beginners fail in string comparison. You may not even be aware of the mistake! ??
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java