Scala Error: java.sql.SQLException: No suitable driver found for jdbc:calcite:

时间:2019-01-18 18:42:19

标签: scala jdbc apache-calcite

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.

2 个答案:

答案 0 :(得分:0)

似乎Apache Flink中存在错误-https://issues.apache.org/jira/browse/FLINK-4581

答案 1 :(得分:0)

尽管我仍然没有找到解决calcite-core驱动程序问题的方法,但是我设法找到了另一种执行jar的方法。

我在我的pom.xml中添加了以下两个插件。 maven-dependency-plugin将所有相关的依赖项jar复制到lib文件夹中,而maven-jar-plugin制作一个可执行的jar文件。

                <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>

注意:添加<mainClass>com.example.MainClass</mainClass>将使manifest.mf了解主类是什么。