0

I am getting an error of java.lang.ClassNotFoundException while working with EJB.

Tools and Technologies:

Eclipse Kepler

EJB 3.0

Oracle 11g

Jboss 7.1.0


I have came across some solutions that adding a ojdbc14.jar/ojdbc6.jar will work.

I have added jar files to the classpath but it is still giving the same exception "java.lang.ClassNotFoundException".

Jboss server log is as given below:


17:27:07,275 ERROR [stderr] (http-localhost-127.0.0.1-8081-1) java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver from [Module "deployment.NewEJB.jar:main" from Service Module Loader]

17:27:07,278 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

17:27:07,279 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)

17:27:07,281 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)

17:27:07,282 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

17:27:07,284 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)

17:27:07,286 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at java.lang.Class.forName0(Native Method)

17:27:07,287 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at java.lang.Class.forName(Class.java:190)

17:27:07,289 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at com.session.LibraryPersistentBean.getList(LibraryPersistentBean.java:39)

17:27:07,291 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

17:27:07,293 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

17:27:07,295 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

17:27:07,298 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at java.lang.reflect.Method.invoke(Method.java:606)

17:27:07,300 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)

17:27:07,304 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,307 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

17:27:07,311 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36)

17:27:07,313 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,314 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)

17:27:07,316 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,317 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

17:27:07,319 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,320 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

17:27:07,322 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)

17:27:07,324 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,327 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)

17:27:07,330 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,333 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228)

17:27:07,336 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304)

17:27:07,338 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190)

17:27:07,340 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,342 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropogatingInterceptor.processInvocation(EJBRemoteTransactionPropogatingInterceptor.java:80)

17:27:07,344 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,345 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)

17:27:07,347 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,349 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)

17:27:07,350 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,353 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)

17:27:07,355 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,357 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)

17:27:07,359 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

17:27:07,361 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

17:27:07,364 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)

17:27:07,365 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.ejb3.remote.LocalEjbReceiver.processInvocation(LocalEjbReceiver.java:179)

17:27:07,367 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:173)

17:27:07,369 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.java:43)

17:27:07,371 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175)

17:27:07,372 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:92)

17:27:07,374 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175)

17:27:07,375 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)

17:27:07,377 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)

17:27:07,379 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

17:27:07,380 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at com.sun.proxy.$Proxy12.getList(Unknown Source)

17:27:07,381 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at com.login.action.LoginAction.execute(LoginAction.java:48)

17:27:07,383 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)

17:27:07,384 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)

17:27:07,386 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)

17:27:07,387 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)

17:27:07,388 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)

17:27:07,390 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)

17:27:07,391 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)

17:27:07,393 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)

17:27:07,394 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)

17:27:07,395 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)

17:27:07,398 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

17:27:07,400 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)

17:27:07,402 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

17:27:07,404 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

17:27:07,405 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

17:27:07,407 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154)

17:27:07,410 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)

17:27:07,416 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

17:27:07,418 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

17:27:07,419 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)

17:27:07,421 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

17:27:07,424 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)

17:27:07,427 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)

17:27:07,430 ERROR [stderr] (http-localhost-127.0.0.1-8081-1)   at java.lang.Thread.run(Thread.java:724)

This is my code:

package com.session;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;

import com.entity.Book;

/**
 * Session Bean implementation class LibraryPersistentBean
 */
@Stateless
public class LibraryPersistentBean implements LibraryPersistentBeanRemote {

    /**
     * Default constructor. 
     */
    public LibraryPersistentBean() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public List<Book> getList() {
        Connection con = null;
        String url = "jdbc:oracle:thin:@localhost:1521:XE";
        String driver = "oracle.jdbc.driver.OracleDriver";

        String userName = "NL";
        String password = "NL";
        List<Book> books = new ArrayList<Book>();
        try {

             Class.forName(driver);
             con = DriverManager.getConnection(url , userName, password);

             Statement st = con.createStatement();
             ResultSet rs = st.executeQuery("SELECT * FROM LOGIN");

             Book book;
             while (rs.next()) {
                book = new Book();
                book.setId(rs.getInt(1));                 
                book.setUsername(rs.getString(2));
                books.add(book);
             }
          } catch (SQLException ex) {
             ex.printStackTrace();
          } catch (ClassNotFoundException ex) {
             ex.printStackTrace();
          }
          return books;
    }
}

Thanks in advance...!

7
  • make sure the ojdbc14.jar/ojdbc6.jar file is in your WEB-INF/lib folder Commented May 26, 2016 at 12:19
  • Yeah I already said that I have added those jar files. Commented May 26, 2016 at 12:23
  • Hey Developers... Please focus on the first line of Jboss server log. Commented May 26, 2016 at 12:25
  • add the full stack trace to your question Commented May 26, 2016 at 12:29
  • Please see first and then comment. I have added the full stack trace. Commented May 26, 2016 at 12:30

1 Answer 1

1

You should create a new module, for your Oracle datasource, into your JBoss 7.1.0. application server.

In order to do that, you need to do the following:

  1. Create a new folder structure: <JBOSS_HOME>/modules/com/oracle/db/main
  2. Copy your OJDBC JAR into your newly created directory mentioned above
  3. Create a file named module.xml, in the directory mentioned in 1.:

    <module xmlns="urn:jboss:module:1.0" name="com.oracle.db">
        <resources>
            <resource-root path="ojdbc.jar"/>
        </resources>
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
        </dependencies>
    </module>
    
  4. Modify your standalone.xml file in order to accommodate the newly created module:

    <subsystem xmlns="urn:jboss:domain:datasources:1.2">
        <datasources>
        (...)
        </datasources>
        <drivers>
            <driver name="oracle" module="com.oracle.db">
                <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
            </driver>
        </drivers>
    </subsystem>
    
  5. Finally, you just need to configure your datasource according to your needs.


Further information can be found in the following links:

Sign up to request clarification or add additional context in comments.

4 Comments

I have done this and datasource is created successfully. But still the error remains the same. I have done debugging of this code. When it reaches the Class.forName("oracle.jdbc.driver.OracleDriver") it skips the further statement and directly gives the "ClassNot FoundException".
Are you using any building tool (Gradle, Maven, etc.) to package your application?
No I m not using any building tools.
That's why then. Your OJDBC JAR isn't binded to your classpath therefore, even though you have it as a module on your JBoss installation, your JAR isn't aware that that module should be used. Why don't you try to convert your project into Maven. Perhaps you can use this as a starting point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.