gpt4 book ai didi

java - 我在使用 EJB 时收到错误 `java.lang.ClassNotFoundException`

转载 作者:行者123 更新时间:2023-12-01 09:53:13 24 4
gpt4 key购买 nike

我在使用 EJB 时收到 java.lang.ClassNotFoundException 错误。

工具和技术:

eclipse 开普勒

EJB 3.0

Oracle 11g

Jboss 7.1.0

<小时/>

我遇到了一些解决方案,添加 ojdbc14.jar/ojdbc6.jar 就可以了。

我已将 jar 文件添加到类路径中,但它仍然给出相同的异常“java.lang.ClassNotFoundException”。

Jboss服务器日志如下:

<小时/>
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)
<小时/>

这是我的代码:

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;
}
}

提前致谢...!

最佳答案

您应该在 JBoss 7.1.0 中为 Oracle 数据源创建一个新模块。应用服务器。

为此,您需要执行以下操作:

  1. 创建新的文件夹结构: /modules/ com/oracle/db/main
  2. 将 OJDBC JAR 复制到上面提到的新创建的目录中
  3. 1.中提到的目录中创建一个名为module.xml的文件:

    <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. 修改您的standalone.xml文件以适应新创建的模块:

    <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. 最后,您只需根据需要配置数据源即可。

<小时/>

更多信息可以在以下链接中找到:

关于java - 我在使用 EJB 时收到错误 `java.lang.ClassNotFoundException`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37460486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com