0

I am banging my head around this, but could not find any solution. I am using jboss-fuse-6.1.0.redhat-379 server and deploying my jar inside Jboss_home/deploy/ folder

The problem I am having is that I am unable to load the oracle ojdbc jar when I run my application. I have tried adding this ojdbc14.jar in my local repository and then adding dependency in POM like:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc14</artifactId>
    <version>10.2.0.4.0</version>
</dependency>

It successfully resolves the imports problem, but when I deploy my jar in Jboss and run my application, it gives an error that:

java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@//ip:port/some_name

I have also tried adding ojdbc.jar like this in POM:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc14</artifactId>
    <version>10.2.0.4.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/ojdbc14-10.2.0.4.0.jar</systemPath>
</dependency>

but still getting the same "No suitable driver found" message. Any help how can I add the ojdbc.jar inside my jar ?

**** Update ****

Java Code:

try
   {
   //   File CP_file = new File("/home/path/to/ojdbc14.jar");
   //   DBFactory dbMethod = new DBFactory();
   //   dbMethod.addJarToClasspath(CP_file);

      Class.forName ("oracle.jdbc.OracleDriver");
      String dbURL = "jdbc:oracle:thin:@//ip:port/name";
      String userID = "userid";
      String password = "pass";

  //  dbMethod.isJarOnClassPath(CP_file);

      Connection dbConnection=DriverManager.getConnection(dbURL,userID,password);
// getting exception on above line
pro_newbie
  • 336
  • 2
  • 6
  • 19
  • https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/Configuring_and_Running_Red_Hat_JBoss_Fuse/files/ESBRuntimeFailoverJdbc.html – James Jithin Feb 19 '17 at 08:27
  • I assume the jar is on the classpath, and the service has been restarted? Can you just try running `Class.forName("oracle.jdbc.driver.OracleDriver");` anywhere before your first connection attempt? This should _hopefully_ create a new instance of the driver. – Matt Clark Feb 19 '17 at 09:10

4 Answers4

1

i have same proplem and i solve it

put this repository in your pom file

   <repository>
       <id>codelds</id>
       <url>https://code.lds.org/nexus/content/groups/main-repo</url>
    </repository>

Then add your dependency

 <!-- ORACLE JDBC driver, need install yourself -->
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.1.0</version>
    </dependency>
salah atwa
  • 86
  • 11
1

You can embed a JAR inside your bundle using Maven Bundle Plugin. This will also take care of adding correct OSGi headers in your manifest.

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Embed-Dependency>ojdbc6</Embed-Dependency>
        </instructions>
    </configuration>
</plugin>

Anyway this is not a good approach. I would recommend using either JPA or adding Oracle JDBC drivers to the lib/ folder and exporting them through the system bundle.

Alessandro Da Rugna
  • 4,571
  • 20
  • 40
  • 64
0

When you use a system-scoped dependency in pom.xml, the jar file of the dependency is not packaged into your binary file. In other words, the jar is not on the classpath.

  1. Try to use the provided-scope of Maven. Then the odbc-jar must be in some lib folder of JBoss, similar to the lib-folder like in Tomcat.

  2. You could to install the odbc-jar into your local Maven repository and then include the dependency with default-scope.

  3. If your scenario is, that the jar is not deployable, because it must be placed on a specific path in the file system, I would try to add the jar-File to classpath during runtime. In another context than yours, I was able to deploy and run my lib with the following snippet.

Until you find something better, it hopefully serves as a work-around:

private boolean addJarToClasspath( File jarFile )
{
    try
    {
        URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
        Class<?> urlClass = URLClassLoader.class;
        Method method = urlClass.getDeclaredMethod( "addURL", new Class<?>[] { URL.class } );
        method.setAccessible( true );
        method.invoke( urlClassLoader, new Object[] { jarFile.toURI().toURL() } );
        System.out.println( jarFile.getAbsolutePath() + " dynamically added to classpath" );
        return true;
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return false;
    }
}

private boolean isJarOnClassPath( File jarFile )
{
    URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    URL[] urls = urlClassLoader.getURLs();
    for ( URL url : urls )
    {
        File file = new File( url.getFile() );
        if ( file.getPath().endsWith( jarFile.getName() ) )
        {
            System.out.println( jarFile.getAbsolutePath() + " is on classpath" );
            return true;
        }
    }
    return false;
}
  • Please see the instructions for [mvn install:install-file](http://stackoverflow.com/a/1074971) for the second approach, which I strongly recommend. This is the Maven-way to deal with third-party libs which are not provided by public repos. Only if that does really not work, we should talk about the third one, which is actually a bad work-around. But really only then. – Alexander Mühlbauer Feb 20 '17 at 13:41
  • Perhaps also a useful info by Oracle itself: [Get Oracle JDBC drivers from the Oracle Maven Repository - NetBeans, Eclipse & Intellij](https://blogs.oracle.com/dev2dev/entry/oracle_maven_repository_instructions_for) – Alexander Mühlbauer Feb 20 '17 at 13:49
0

you can use wrap protocol to install in karaf

osgi:install -s wrap:mvn:groupid/artifactid/version
Ramu
  • 26
  • 2