Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include redshift jdbc driver: Unable to instantiate driver class "com.amazon.redshift.jdbc.Driver": java.lang.NoClassDefFoundError

We use Wildfly 10 with a postgres datasource (postgres driver is deliverd in /modules folder) and in addition, a Redshift DB should be attached.

So I followed Configure a JDBC Connection with Apache Maven :
My parent POM includes therefore:

<repositories>
    ...
    <repository>
        <id>redshift</id>
        <url>http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release</url>
    </repository>
</repositories>

and

<dependencies>
    ...
    <dependency>
        <groupId>com.amazon.redshift</groupId>
        <artifactId>redshift-jdbc42</artifactId>
        <version>1.2.10.1009</version>
    </dependency>
</dependencies>

If I know deploy me .war file, the following warning appears very early in the log:

INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)
INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.2)
WARN  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0003: Unable to instantiate driver class "com.amazon.redshift.jdbc.Driver": java.lang.NoClassDefFoundError: com/amazon/redshift/core/jdbc42/PGJDBC42DriverImpl

So no wonder that later on, if I try to access the DB, I get

ERROR [stderr] (default task-64) java.sql.SQLException: No suitable driver found for jdbc:redshift://....
ERROR [stderr] (default task-64)    at java.sql.DriverManager.getConnection(DriverManager.java:689)
ERROR [stderr] (default task-64)    at java.sql.DriverManager.getConnection(DriverManager.java:208)

So what am I doing wrong? The driver is packaged in the .war, this is for sure, otherwise, there would not be a trial to instantiate it during deployment. Any help is highly appreciated!!

like image 262
badera Avatar asked Dec 09 '25 21:12

badera


1 Answers

Apparently the redshift-jdbc42 dependency has been packaged with "inner" JAR files, and this causes problems for class loading in some contexts. Try replacing

    <dependency>
        <groupId>com.amazon.redshift</groupId>
        <artifactId>redshift-jdbc42</artifactId>
        <version>${amazon.redshift.version}</version>
    </dependency>

with

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-redshift</artifactId>
        <version>${amazonaws.sdk.version}</version>
    </dependency>
    <dependency>
        <groupId>com.amazon.redshift</groupId>
        <artifactId>redshift-jdbc42-no-awssdk</artifactId>
        <version>${amazon.redshift.version}</version>
    </dependency>

(Source: https://forums.aws.amazon.com/thread.jspa?threadID=263573)

like image 105
Stephen C Avatar answered Dec 11 '25 11:12

Stephen C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!