我正在处理一个项目(使用JavaEE,jboss和maven的桌面应用程序),并且试图显示数据库中的数据。它显示了ClassNotFoundException,我使用system.out.println(“ hello”)来查看代码在哪里崩溃,然后得出结论,它位于“ students = proxy.getStudents();”中。线。谁能给我解释一下是什么问题。我什至尝试将List()更改为ArrayList(),因为我在这里读到List()不能直接实例化,无论哪种方式代码都无法工作。我也有警告[资源路径位置类型 类路径条目C:/ Program Files / Java / jdk1.8.0_181 / lib / javafx-mx.jar被标记为发布/导出,但未在项目类路径上导出。 Eclipse中和运行时的类路径可见性将有所不同。 [student_placement_platform-ejb P / student_placement_platform-ejb类路径依赖项验证程序消息],在一些论坛上阅读后,我得出的结论是我的项目没有阅读persistence.xml,因此我将其放在src / java /下的META-INF下资源。
这是我的main.java:
package tn.esprit.student_placement_platform_client.tests;
import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import tn.esprit.student_placement_platform.entities.User;
import tn.esprit.student_placement_platform.iservices.FormServicesRemote;
public class FormTest {
public static void main(String[] args) throws InterruptedException, NamingException {
String jndiName = "student_placement_platform-ear/student_placement_platform-ejb/FormServices!tn.esprit.student_placement_platform.iservices.FormServicesRemote";
Description Resource Path Location Type
Classpath entry C:/Program Files/Java/jdk1.8.0_181/lib/javafx-mx.jar is marked for publish/export but is not exported on the project classpath. Classpath visibility within Eclipse and at runtime will differ. student_placement_platform-ejb P/student_placement_platform-ejb Classpath Dependency Validator Message
Description Resource Path Location Type
Console configuration "student_placement_platform-ejb" does not exist. Hibernate specific validation and content assist will be limited. student_placement_platform-ejb line 0 JPA Problem
Description Resource Path Location Type
No connection specified for project. No database-specific validation will be performed. student_placement_platform-ejb JPA Problem
Context context = new InitialContext();
FormServicesRemote proxy = (FormServicesRemote) context.lookup(jndiName);
List<User> students = null;
students = proxy.getStudents();
//System.out.println("here");
proxy.displayAll(students);
这是运行main.java之后的控制台:
avr. 03, 2019 7:03:38 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.0.Beta2
avr. 03, 2019 7:03:38 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.0.Beta2
avr. 03, 2019 7:03:38 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.5.Beta1
avr. 03, 2019 7:03:38 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
avr. 03, 2019 7:03:38 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@370736d9, receiver=Remoting connection EJB receiver [connection=Remoting connection <a0f2de5>,channel=jboss.ejb,nodename=desktop-nosg5hn]} on channel Channel ID b1f98621 (outbound) of Remoting connection 339d465a to /127.0.0.1:18080
avr. 03, 2019 7:03:39 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.0.1.Final
Exception in thread "main" javax.ejb.EJBException: java.lang.ClassNotFoundException: org.hibernate.PropertyAccessException
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:236)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
at com.sun.proxy.$Proxy2.getStudents(Unknown Source)
at tn.esprit.student_placement_platform_client.tests.FormTest.main(FormTest.java:19)
Caused by: java.lang.ClassNotFoundException: org.hibernate.PropertyAccessException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:131)
at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:112)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:949)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1256)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1746)
at org.jboss.marshalling.river.RiverObjectInputStream.defaultReadObject(RiverObjectInputStream.java:81)
at java.lang.Throwable.readObject(Throwable.java:914)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1638)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1286)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1746)
at org.jboss.marshalling.river.RiverObjectInputStream.defaultReadObject(RiverObjectInputStream.java:81)
at java.lang.Throwable.readObject(Throwable.java:914)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1638)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1286)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
at org.jboss.ejb.client.remoting.InvocationExceptionResponseHandler$MethodInvocationExceptionResultProducer.getResult(InvocationExceptionResponseHandler.java:79)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:276)
at org.jboss.ejb.client.EJBObjectInterceptor.handleInvocationResult(EJBObjectInterceptor.java:64)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
at org.jboss.ejb.client.EJBHomeInterceptor.handleInvocationResult(EJBHomeInterceptor.java:88)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:46)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:129)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:265)
at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:453)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:20
``````````````````````````````````````````
this is my service class:
``````````````````````````````````
package tn.esprit.student_placement_platform.services;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import tn.esprit.student_placement_platform.entities.Category;
import tn.esprit.student_placement_platform.entities.Document;
import tn.esprit.student_placement_platform.entities.User;
import tn.esprit.student_placement_platform.iservices.FormServicesRemote;
@Stateless
@Remote
public class FormServices implements FormServicesRemote {
@PersistenceContext(unitName = "student_placement_platform-ejb")
EntityManager em;
@Override
public Document addForm(Document form) {
em.persist(form);
return form;
}
@Override
public Category addCategory (Category cat) {
em.persist(cat);
return cat;
}
@Override
public ArrayList<User> getStudents(){
return (ArrayList<User>) em.createQuery("select u from User u", User.class).getResultList();
}
@Override
public void displayAll(List<User> l) {
for(Object u : l){
System.out.println(u);
}
}
}
````````````````````````````````````````````
and finally my interface:
``````````````````````````````````
package tn.esprit.student_placement_platform.iservices;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Remote;
import tn.esprit.student_placement_platform.entities.Category;
import tn.esprit.student_placement_platform.entities.Document;
import tn.esprit.student_placement_platform.entities.User;
@Remote
public interface FormServicesRemote {
public Document addForm(Document form);
public Category addCategory(Category cat);
public ArrayList<User> getStudents();
public void displayAll(List<User> students);
}
````````````````````````````````