1

Within a Vert.x application (running on Windows 10), I'm trying to use a JDBCClient to get a connection to a Microsoft SQL Server 2008 R2.

These are the steps I did so far to accomplish this:

  1. Download the JDBC driver from https://www.microsoft.com/en-us/download.
  2. Set environment variable CLASSPATH=<path>/mssql-jdbc7.0.0.jre8.jar
  3. Add dependencies for JDBC Client and jdbc driver into pom.xml file.
  4. Compile app with the command: mvn clean package from project home
  5. Run app with java -jar ./target/<app-name>-SNAPSHOT-fat.jar

Here is app pom.xml dependency:

<dependency>
 <groupId>io.vertx</groupId>
 <artifactId>vertx-jdbc-client</artifactId>
</dependency>
<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>7.0.0.jre8</version>
</dependency>

and the code snippet to create client and get connection:

JDBCClient client = JDBCClient.createShared(
       vertx,
       new io.vertx.core.json.JsonObject()
           .put("url", "jdbc:sqlserver://192.168.1.180;databaseName=<dbname>;user=<usr>;password=<psw>")
           .put("driver_class", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
   );
   client.getConnection(res -> {
       if (res.succeeded())
           System.out.println("Connection opened");
       else {
           try {
               System.out.println("Connection failed");
               throw res.cause();
           } catch (Throwable e) {System.out.println(e.getMessage());}
       }
   });

Once I run the app i get the following error:

>java -jar .\target\mssql-1.0.0-SNAPSHOT-fat.jar
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
        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.ensureInitialization(Unknown Source)
        at java.util.jar.JavaUtilJarAccessImpl.ensureInitialization(Unknown Source)
        at sun.misc.URLClassPath$JarLoader$2.getManifest(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(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)

Someone can tell me were I'm wrong?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
mcelia
  • 13
  • 3
  • 2
    This error has nothing to do with vertx and jdbc driver. YOu are having other issue here. Please refer to https://stackoverflow.com/questions/34855649/invalid-signature-file-digest-for-manifest-main-attributes-exception-while-tryin/34856095 – Pendula Jul 05 '19 at 21:49
  • Are you trying to create a fat jar? Please post the complete pom.xml. – Mark Rotteveel Jul 06 '19 at 05:49

2 Answers2

0

I solve the problems, here is the step-by-step general procedure for integrating an external and signed jar into a vertx project that is compiled and run using maven:

  1. From the project main directory create a different local Maven repository with:
mvn deploy:deploy-file -Dfile=<path-to-.jar-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=jar -Durl=file:./extlib/ -DrepositoryId=extlibid -DupdateReleaseInfo=true
  1. Then add the following repository into pom.xml :
<repositories>
    <repository>
        <id>extlibid</id>
        <url>file:///${project.basedir}/extlib</url>
    </repository>
</repositories>
  1. Now add the dependency for the external jar:
...
<dependency>
    <groupId>com.sample.example</groupId>
    <artifactId>example-app</artifactId>
    <version>1.0</version>
</dependency>
...
  1. Finally, and most important, exclude different signatures if external jar is signed on its own
...
<plugin>
 <artifactId>maven-shade-plugin</artifactId>
 <version>${maven-shade-plugin.version}</version>
 <executions>
  <execution>
  <phase>package</phase>
  <goals>
   <goal>shade</goal>
  </goals>
 <configuration>
...
<filters>
 <filter>
  <artifact>*:*</artifact>
  <excludes>
   <excludes>META-INF/*.SF</excludes>
   <excludes>META-INF/*.DSA</excludes>
   <excludes>META-INF/*.RSA</excludes>
  </excludes>
 </filter>
</filters>
...
mcelia
  • 13
  • 3
0

AFAIK jdbc is a blocking driver. You will lost all benefits of using async web server.

Marek Marczak
  • 532
  • 8
  • 14