-5

I have a stand-alone java application that uses ojdbc6.jar to connect to Oracle. Using Maven to compile the application works fine, and debugging the project in Eclipse works fine.

However, using Maven package to bundle the dependencies and then running the application from the command line I get the exception: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@::

The jar containing the dependencies exists and the correct path to this artifact is propertly specified in the classpath. Upon examination of the dependency jar file I can see the Oracle folder with the correct files, so apparently the packaging included the drivers but Java can't find them. Adding a classpath entry pointing directly to the file ojdbc6.jar allows the program to run fine, so there is no issue with any of the other dependencies. So it really seems like the problem lies with the packaging.

Anyone ever run into anything like this?

Here is the POM:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>MyGroup</groupId>
    <artifactId>MyArtifact</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax.jcr</groupId>
            <artifactId>jcr</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-core</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.11</version>
        </dependency>
        <dependency>
            <groupId>diss</groupId>
            <artifactId>diss-eai-interface</artifactId>
            <version>4.3</version>
        </dependency>
        <dependency>
            <groupId>diss</groupId>
            <artifactId>diss-jvs-datadictionary</artifactId>
            <version>4.3</version>
        </dependency>
        <dependency>
            <groupId>diss</groupId>
            <artifactId>diss-cats-model</artifactId>
            <version>4.3</version>
        </dependency>
        <dependency>
            <groupId>diss</groupId>
            <artifactId>diss-common-ui</artifactId>
            <version>4.3</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>3.5.28</version>
        </dependency>
        <dependency>
            <groupId>diss</groupId>
            <artifactId>diss-eai-business</artifactId>
            <version>4.3</version>
        </dependency>
        <dependency>
            <groupId>weblogic</groupId>
            <artifactId>wlfullclient</artifactId>
            <version>10.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.4.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>commonj.sdo</artifactId>
                    <groupId>commonj.sdo</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>catalina</artifactId>
            <version>6.0.18</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>diss</groupId>
            <artifactId>diss-jvs-model</artifactId>
            <version>4.3</version>
        </dependency>



        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.0.2</version>
        </dependency>

        <dependency>
            <groupId>aspose</groupId>
            <artifactId>word</artifactId>
            <version>14.1.0</version>
        </dependency>


      </dependencies>

    <build>



    <plugins>


      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <downloadSources>true</downloadSources>
          <downloadJavadocs>false</downloadJavadocs>
        </configuration>
      </plugin>


      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>


            <!-- prevent Invalid signature exception -->
            <configuration>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                    <excludes>
                      <exclude>META-INF/*.SF</exclude>
                      <exclude>META-INF/*.DSA</exclude>
                      <exclude>META-INF/*.RSA</exclude>
                    </excludes>
                </filter>
              </filters>
            </configuration>

          </execution>
        </executions>
        <configuration>
          <finalName>uber-${project.artifactId}-${project.version}</finalName>
        </configuration>
      </plugin>


    </plugins>


    </build>




    <repositories>


        <repository>
            <id>EclipseLink Repo</id>
            <url>http://download.eclipse.org/rt/eclipselink/maven.repo</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>

        <repository>
            <id>Apache-Maven</id>
            <layout>default</layout>
            <url>https://repository.apache.org/content/repositories/releases/</url>
        </repository>

        <repository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>

    </repositories>


</project>
  • 2
    `pom` file and directory layout would probably be helpful in this case. – Compass Dec 15 '14 at 19:43
  • Besides the fact that a ojdbc6.jar is not in Maven repository I also wonder how you actually package/start your application. Because normally (when not using a shader or launcher) dependencies have to be specified manually (in the java classpath). – eckes Dec 15 '14 at 19:54
  • define *"Maven package"* this is not standard maven jargon. Without the relevant bits of `pom.xml` and a listing of what is in your `~/.m2/repository` directory, this will get closed. –  Dec 15 '14 at 20:00
  • Thanks, eckes...As mentioned in the original post, I already have possession of the ojdbc file, and it <<>> to be packaged in the jar that is created when calling Maven package. – oldJavaDude Dec 15 '14 at 20:01
  • @oldJavaDude please post your pom.xml file. – fmodos Dec 15 '14 at 20:02
  • edit your question and paste the contents of your `pom.xml` in a properly formatted code block. –  Dec 15 '14 at 20:04
  • did you read this? -> http://stackoverflow.com/questions/9898499/oracle-jdbc-ojdbc6-jar-as-a-maven-dependency?rq=1 –  Dec 15 '14 at 20:05
  • Hi Jarod, thanks...I'm literally calling the Maven package phase from the default lifecycle, here is the command: mvn package – oldJavaDude Dec 15 '14 at 20:06
  • `.jar/.ear/.war` files are called `artifacts` not `maven packages`, and you still have not posted your `pom.xml` as an edit to your question! –  Dec 15 '14 at 20:10
  • Thanks Jarrod, trying to post the POM now...give me a minute. – oldJavaDude Dec 15 '14 at 20:12

2 Answers2

3

It is not possible to download Oracle ojdbc jar from a public repository because of License Agreement, it is necessary to install manually in your local repository using maven install (more info here). If you use nexus, it can be uploaded using its admin layout.

The oracle jdbc jar can be downloaded from here

fmodos
  • 4,472
  • 1
  • 16
  • 17
  • Thanks fmodos -- as mentioned in the original post I already have possession of the ojdbc jar and have installed it in my local repository. – oldJavaDude Dec 15 '14 at 19:58
  • no the problem lies with your configuration of the maven project and/or the way you are starting your application if it is not in an app server; as I have no problems with this same `.jar` in any of my multiple maven managed projects that require it. –  Dec 15 '14 at 20:01
2

You are not using Maven idiomatically that is most of your problem:

You are not using the default behavior of Maven to build and package a .jar file. You are using the assembly plugin for apparently no reason and you are using it incorrectly on top of that. It is not building what maven would build by default.

Idiomatic:

  1. Define <packaging>jar</packaging> and get rid of the assembly plugin.

  2. You should be using the shade plugin to make a uber-jar, and building a custom manifest using the default packaging system to define the entry point.

  3. Resources should go in /src/main/resources not in with the source code. If it is done this way there is nothing to configure as that is the expected location for non-source files. Get rid of the <resources/> stanza.

You should not have to ever use the assembly plugin unless you are doing some really advanced thing, and then you would probably just write your own plugin to do it.

These are just three of many the problems you are committing in this pom.xml.

Community
  • 1
  • 1
  • Hello Jarrod, thank you for the in-depth suggestions -- updated pom posted above. Unfortunately, I still get the same issue when using the Shade plugin, the ojdbc6 driver appears in the uber jar, but is not recognized when attempting to run the program. – oldJavaDude Dec 16 '14 at 19:49