问题
I'm trying to use bacnet4j with JSF.
I build an application in .java which turn on/off a lamp, but if I try to call the same method from a JSF page (which communicates with my manage bean) , gives me :
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: com/serotonin/bacnet4j/type/Encodable
root cause
java.lang.NoClassDefFoundError: com/serotonin/bacnet4j/type/Encodable
root cause
java.lang.ClassNotFoundException: com.serotonin.bacnet4j.type.Encodable
But I'm pretty sure that the class is there, because if not my java application don't work, right ?
Any idea why this is happening ?
回答1:
The JAR file containing this class should go in webapp's /WEB-INF/lib folder.
A plain Java Application does not use the same classpath as a Java Web Application. For a plain Java Application the classpath is usually specified by -cp or -classpath argument in java command, or if unspecified, by %CLASSPATH% environment variable, or if being a JAR, by Class-Path entry in JAR's /META-INF/MANIFEST.MF. For a Java Web Application the classpath covers by default the webapp's /WEB-INF/lib and /WEB-INF/classes folder and server's /lib (and more) folders and any custom folders which you can specify in server-specific configuration, such as shared.loader property of /conf/catalina.properties in case of Tomcat.
回答2:
NoClassDefFound means that the class was available at compilation but not at runtime. You need to add the jar-file with the appropriate class to your war (or add it to the application server classpath)
来源:https://stackoverflow.com/questions/8942680/class-found-in-a-java-application-but-not-in-jsf