2016-05-26 6 views
0

Ich erhalte einen Fehler von java.lang.ClassNotFoundException während der Arbeit mit EJB.Ich bekomme einen Fehler von `java.lang.ClassNotFoundException` während der Arbeit mit EJB

Tools und Technologien:

Eclipse-Kepler

EJB 3.0

Oracle 11g

Jboss 7.1.0


ich auf einige Lösungen kam, hinzufügen Eine ojdbc14.jar/ojdbc6.jar wird funktionieren.

Ich habe JAR-Dateien zum Classpath hinzugefügt, aber es gibt immer noch die gleiche Ausnahme "java.lang.ClassNotFoundException".

Jboss-Server-Protokoll wird wie unten angegeben:


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) 

Dies ist mein 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; 
    } 
} 

Vielen Dank im Voraus ...!

+0

sicherstellen, dass die ojdbc14.jar/ojdbc6.jar Datei in Ihrem WEB-INF/lib-Ordner –

+0

Ja, ich sagte bereits, dass ich diese JAR-Dateien hinzugefügt habe. –

+0

Hey Entwickler ... Bitte konzentrieren Sie sich auf die erste Zeile des Jboss Server Logs. –

Antwort

1

Sie sollten ein neues Modul für Ihre Oracle-Datenquelle in Ihrem JBoss 7.1.0 erstellen. Anwendungsserver.

Um das zu tun, müssen Sie Folgendes tun:

  1. Erstellen Sie eine neue Ordnerstruktur: <JBOSS_HOME>/modules/com/oracle/db/main
  2. Kopieren Sie Ihre OJDBC JAR in die neu erstellte Verzeichnis oben
  3. erwähnt
  4. erstellen Sie eine Datei module.xml benannt, in dem Verzeichnis, in 1. erwähnt:

    <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> 
    
  5. Ändern Sie bitte Ihre standalone.xml-Datei, um das neu erstellte Modul zur Aufnahme von:

    <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> 
    
  6. Schließlich brauchen Sie nur Ihre Datenquelle nach Ihren Bedürfnissen zu konfigurieren.


Weitere Informationen finden Sie in den folgenden Links zu finden:

+0

Ich habe dies getan und die Datenquelle wurde erfolgreich erstellt. Trotzdem bleibt der Fehler gleich. Ich habe das Debuggen dieses Codes durchgeführt. Wenn es den 'Class.forName (" oracle.jdbc.driver.OracleDriver ") erreicht, überspringt es die weitere Anweisung und gibt direkt die" ClassNot FoundException "aus. –

+0

Verwenden Sie ein Bauwerkzeug (Gradle, Maven usw.) zum Verpacken Ihrer Anwendung? – aribeiro

+0

Nein Ich verwende keine Bauwerkzeuge. –