0

I created a jar of a Scala application using maven-assembly-plugin. Now when I execute the jar with java -jar path\to\jar\myapp.jar it throws the following error:

Exception in thread "main" Exception in thread "Timer-0" java.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:calcite:
        at org.apache.calcite.tools.Frameworks.withPrepare(Frameworks.java:159)
        at org.apache.calcite.tools.Frameworks.withPlanner(Frameworks.java:114)
        Caused by: java.sql.SQLException: No suitable driver found for jdbc:calcite:
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at org.apache.calcite.tools.Frameworks.withPrepare(Frameworks.java:153)
        ... 17 more
java.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:calcite:
        at org.apache.calcite.tools.Frameworks.withPrepare(Frameworks.java:159)
        at org.apache.calcite.tools.Frameworks.withPlanner(Frameworks.java:114)
        at java.util.TimerThread.mainLoop(Unknown Source)
        at java.util.TimerThread.run(Unknown Source)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:calcite:
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at org.apache.calcite.tools.Frameworks.withPrepare(Frameworks.java:153)
        ... 8 more

When I run the application through an IDE (IntelliJ) it works fine.

Can anyone tell me why this is happening?

EDIT1: I opened the jar file and saw that the calcite-core jar is present in org/apache/calcite jar.

EDIT2: I tried changing the version of calcite-core. I was using 1.15.0 earlier and now I'm using 1.18.0 but the error is still there.

  • Can you open your jar file (it should be possible to open it using any application, that can extract zip files) and check is there is directory `org/apache/calcite` inside? – Krzysztof Atłasik Jan 18 '19 at 20:18
  • _"The calcite-core jar is present in my classpath."_ **How** is it present on the class path according to you? The error indicates it isn't, and because you are using `java -jar path\to\jar\myapp.jar`, the application will only use the classpath defined in `META-INF/manifest.mf`, not any external methods of defining classpath. For example having it in the environment variable `CLASSPATH` will not work, because the `-jar` option doesn't use that. – Mark Rotteveel Jan 19 '19 at 10:44
  • I checked out the `manifest.mf` file. You were right. Having it or not having it in the `CLASSPATH` doesn't matter. But I opened my jar file and checked the `org/apache/calcite` directory. It is present there. What baffles me is that when I am running it on my IDE it's working and `calcite-core` is being detected but not when I am packaging it using Maven and running it. –  Jan 19 '19 at 21:13

2 Answers2

1

Although I still haven't found a solution to the calcite-core driver problem, I managed to find another way to execute the jar.

I added the following two plugins to my pom.xml. The maven-dependency-plugincopies all the relevant dependency jars into a lib folder and the maven-jar-plugin makes a single executable jar file.

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <configuration>
                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                    <excludeTransitive>false</excludeTransitive>
                    <stripVersion>false</stripVersion>
                </configuration>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.example.MainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

Note: Adding <mainClass>com.example.MainClass</mainClass> will make manifest.mf aware of what the main class is.

0

Seems there is a bug in the Apache Flink - https://issues.apache.org/jira/browse/FLINK-4581

Ramesh Subramanian
  • 944
  • 1
  • 12
  • 28