14 Replies Latest reply: Jul 2, 2012 1:41 PM by papablopo RSS

java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver

papablopo Newbie

Hello I newbie with jboss and java, im programming an aplication ion jboss 7.1, im having a problem when try to create my connection

 

this its ok, config the master database connection using jndi

 

public ConexionDirecta(){

       

            InitialContext cxt;

            try {

            cxt = new InitialContext();

           

           

            DataSource ds = (DataSource) cxt.lookup( "java:jboss/datasources/OracleDSJNDI");

            ds.setLoginTimeout(5);

            conn = ds.getConnection();

 

            /*

            try {

                Class.forName("oracle.jdbc.OracleDriver").newInstance();

            } catch (InstantiationException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            } catch (IllegalAccessException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            } catch (ClassNotFoundException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }

          

            System.out.println("conexion con la base EXITOSA " + conn.hashCode());

        } catch (SQLException ex) {

            ex.printStackTrace();

        } catch (NamingException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

    }

 

 

but i need to create another connection, depending, we have 500 databases, one per store, im trying this.

 

public ConexionDirecta(Long sBarrio){

        final String DB_DRIVER_CLASS = "oracle.jdbc.OracleDriver";

         RespuestaServidorFarmacia rsf= cg.getServidorFarmacia(sBarrio);

        

         if (rsf.getiError()==1){

             System.out.println("Error al traer parametros de conexion");

             return;

         }

        

        

        final String DB_URL = "jdbc:oracle:thin:user/pass@"+rsf.getsIp()+":1521"+":"+rsf.getsSid();

 

        conn = null;

 

        try {

           

            // Load the Driver.

           // Class.forName(DB_DRIVER_CLASS).newInstance();

             //Class.forName("oracle.jdbc.OracleDriver").newInstance();

           

            //Class.forName (DB_DRIVER_CLASS);

            DriverManager.registerDriver (new oracle.jdbc.OracleDriver());

           

            conn= DriverManager.getConnection(DB_URL);;

 

        } catch (SQLException se) {

             System.out.println("Error al traer parametros de conexion");

        } catch (Exception e) {

             System.out.println("Error al traer parametros de conexion");

        }

 

 

    }

 

i tried a lot of methods, i read an lot of post here and in other pages, but i cant resolve why i getting this error, we dont want to use jndi because every connection data are stored at the master database, want to do a programatically connection, please help me dont know what to do.

 

thanks for ur time.

 

 

org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver

org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:340)

org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214)

org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190)

org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:540)

org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)

org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)

org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)

org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)

org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)

javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)

causa raíz

java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
     com.gpf.hubFacturacionPart3.ConexionDinamica.ConexionDirecta.<init>(ConexionDirecta.java:90)
     com.gpf.hubFacturacionPart3.rest.WebResourceRESTService.getConfiguracionFarmaciaCercana(WebResourceRESTService.java:96)
     com.gpf.hubFacturacionPart3.rest.WebResourceRESTService$Proxy$_$$_WeldClientProxy.getConfiguracionFarmaciaCercana(WebResourceRESTService$Proxy$_$$_WeldClientProxy.java)
     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     java.lang.reflect.Method.invoke(Method.java:597)
     org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155)
     org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)
     org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
     org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
     org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)
     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
     org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
     org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)

causa raíz

java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver from [Module "deployment.HUBFacturacion.war:main" from Service Module Loader]
     org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
     org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
     org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
     org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
     org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
     org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
     com.gpf.hubFacturacionPart3.ConexionDinamica.ConexionDirecta.<init>(ConexionDirecta.java:90)
     com.gpf.hubFacturacionPart3.rest.WebResourceRESTService.getConfiguracionFarmaciaCercana(WebResourceRESTService.java:96)
     com.gpf.hubFacturacionPart3.rest.WebResourceRESTService$Proxy$_$$_WeldClientProxy.getConfiguracionFarmaciaCercana(WebResourceRESTService$Proxy$_$$_WeldClientProxy.java)
     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     java.lang.reflect.Method.invoke(Method.java:597)
     org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155)
     org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)
     org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
     org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
     org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)
     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
     org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
     org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
  • 1. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    David Salter Novice

    Looks like you've not got the Oracle driver on your class path.  If you're developing a web app, you can put it in your WEB-INF/lib folder.

     

    If you want to access Oracle outside of a web app, you will need to install the driver as a module.  See:

     

    https://community.jboss.org/wiki/DataSourceConfigurationInAS7

  • 2. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    papablopo Newbie

    i tried this:

     

    Put the ojdbc6.jar in deployments path

    in standalone.xml have this

     

    <datasource jta="true" jndi-name="java:jboss/datasources/OracleDSJNDI" pool-name="DesarrolloDS_Pool" enabled="true" use-java-context="true" use-ccm="true">

                        <connection-url>jdbc:oracle:thin:@ipserver:1521:lego_f2</connection-url>

                        <driver>ojdbc6.jar</driver>

                        <pool>

                            <min-pool-size>10</min-pool-size>

                            <max-pool-size>100</max-pool-size>

                            <prefill>false</prefill>

                            <use-strict-min>false</use-strict-min>

                            <flush-strategy>FailingConnectionOnly</flush-strategy>

                        </pool>

                        <security>

                            <user-name>user</user-name>

                            <password>pass</password>

                        </security>

                    </datasource>

    it is ok when use the lookup, but no with loader class

  • 3. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    David Salter Novice

    I imagine this is a class loading issue.  Have you checked out:

     

    https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

     

    How are you deploying your app?  WAR, JAR, EAR?

  • 4. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    papablopo Newbie

    thank you for answering, its a war deploy

  • 5. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    papablopo Newbie

    the problem persist, another sugestion the proyect is in eclipse indigo

  • 6. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    guinotphil Apprentice

    Have you created a module for your Oracle driver ?

  • 7. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    papablopo Newbie

    Yes, but dont know why

     

    Class.forName("oracle.jdbc.OracleDriver").newInstance();

     

    dont work.

     

    error:

    java.lang.ClassNotFoundException: com.oracle.ojdbc6 from [Module "deployment.HUBFacturacion.war:main" from Service Module Loader]

     

    this way

     

    thanks for ur time, this is the standalone.xml driver config

     

    <driver name="oracle" module="com.oracle.ojdbc6">

                            <xa-datasource-class>oracle.jdbc.OracleDriver</xa-datasource-class>

    </driver>

     

    this is the module config

    c:\jboss-as-7.1.0.Final\modules\com\oracle\ojdbc6\main\

    <?xml version="1.0" encoding="UTF-8"?>

    <module xmlns="urn:jboss:module:1.0" name="com.oracle.ojdbc6">

        <resources>

            <resource-root path="ojdbc6.jar"/>

        </resources>

        <dependencies>

            <module name="javax.api"/>

            <module name="javax.transaction.api"/>

        </dependencies>

    </module>

     

    whyyyyyy? xD

  • 8. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    Stephen Coy Master

    JBoss can see the Oracle classes because you told it which module they are in the <driver>...</driver> section.

     

    This doesn't mean your application can see these classes as it would not normally need to be able to do this.

     

    Therefore, you need to add a module dependency to your application in a jboss-deployment-structure.xml as described in Class Loading in AS7 which was previously suggested by David Salter.

  • 9. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    papablopo Newbie

    Thanks Stephen, i have in c:\jboss-as-7.1.0.Final\standalone\deployments\HUBFacturacion.war\WEB-INF\classes\META-INF\

     

    jboss-deployment-structure.xml

     

    <?xml version="1.0" encoding="UTF-8"?>

    <jboss-deployment-structure>

      <deployment>

        <dependencies>

          <module name="oracle.jdbc" />

          <module name="oracle.jdbc.OracleDriver" />

        </dependencies>

        <resources>

            <resource-root path="ojdbc6.jar"/>

        </resources>

       </deployment>

    </jboss-deployment-structure>

     

    its ok?  i still having the error

  • 10. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    Tomaz Cerar Master

    Hi,

     

    fix your jboss-deployment-structure.xml to this:

     

    <?xml version="1.0" encoding="UTF-8"?>

    <jboss-deployment-structure>

      <deployment>

        <dependencies>

          <module name="com.oracle.ojdbc6" />

        </dependencies>

        <resources>

            <resource-root path="ojdbc6.jar"/>

        </resources>

       </deployment>

    </jboss-deployment-structure>

     

    cheers,

    tomaz

  • 11. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    papablopo Newbie

    Thanks Tomaz, im done, when i try to load the class

     

    Class.forName(DB_DRIVER_CLASS).newInstance();

     

     

    which is the DB_DRIVER_CLASS??

     

    i am having problems when try

    "com.oracle.ojdbc6"

    "oracle.jdbc.OracleDriver"

     

    thanks a lot.

  • 12. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    Tomaz Cerar Master

    Hi,

     

    You are confuzing module names and class names. looking more closly on what you have posted so far...

    given the fact that you have allready created module which has oracle driver (jar) in it.

    You can trim the jboss-deployment-structure.xml even more. it should be just this:

     

    <?xml version="1.0" encoding="UTF-8"?>

    <jboss-deployment-structure>

      <deployment>

        <dependencies>

          <module name="com.oracle.ojdbc6" />

        </dependencies>

       </deployment>

    </jboss-deployment-structure>

     

    and this "com.oracle.ojdbc6" is name of module you have created for oracle jdbc driver, it is same module you use when defining datasource and lookup it trough jndi. also you do *not* need ojdbc6.jar to be part of your application it is enough for it just to be in module you defined.

     

    using driver directly can be then done just by

     

    Class.forName ("oracle.jdbc.OracleDriver")

    or by doing:

    DriverManager.registerDriver (new oracle.jdbc.OracleDriver());

     

    hope this helps,

    tomaz

  • 13. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    papablopo Newbie

    Yes i learn some things thanks to all but when i try in that way got this error

     

    riverManager.registerDriver (new oracle.jdbc.OracleDriver());

     

    Class.forName ("oracle.jdbc.OracleDriver")

     

     

    ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/HUBFacturacion].[com.gpf.hubFacturacionPart3.rest.JaxRsActivator]] (http--127.0.0.1-8080-1) Servlet.service() para servlet com.gpf.hubFacturacionPart3.rest.JaxRsActivator lanzó excepción: org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver

     

    the ojdbc6.jar its in the java build path

  • 14. Re: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
    papablopo Newbie

    Hi people, i can resolve, i create an EAR proyect selected the main proyect andproyect.png

    in libraries put the ojdbc6.jar thanks for ur help.