What do I need to include in Tomcat 7 to get javax.persistence working correctly?

扶醉桌前 提交于 2021-02-05 11:38:35

问题


I'm attempting to build a JSF/Hibernate application using Java 7 and Tomcat 7. I have installed the Java SDK and the JavaEE SDK, and copied the javaee.jar and javaee-api-6.jar into my Tomcat LIB folder. By my understanding of this post and this post I should have all of the jars I need, and to the best of my knowledge I have no other jars in this folder that have conflicting resources.

  • The javaee.jar file contains what looks like a Maven pom file, and nothing else. I'm not sure what its value is.

  • My javaee-api-6 jar is about 950k in size, and contains all of the .class files I would expect it to. The code I'm using compiles fine, I only see an error when attempting to deploy to Tomcat. These jars were taken from a glassfish installation. Curiously the file ServletException.class file is only 366 bytes.

  • I've set up Tomcat in Eclipse such that the IDE will 'take over' Tomcat when deploying, instead of deploying to some plug-in folder (default behavior).

  • The only relevant packages I'm using thusfar are 'Entity' 'Id' and 'GeneratedValue' from javax.persistence.

  • I've tried using only javaee-api-6.jar and renamed it javaee-api.jar and javaee.jar with no change. The filename it seems, is unimportant.

A deeper inspection of the Glassfish lib folder does show a number of relevant-looking jars, but not the complete javaee package, so I cant move the Javaee-api-6.jar out and move them in, they're incomplete and I get a similar error indicating (I'm assuming) that the implementation of some class can't be found.

So my question is: What do I need to include in Tomcat 7 to get javax.persistence working correctly ?

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.getMethods(Unknown Source)
at org.apache.tomcat.util.IntrospectionUtils.findMethods(IntrospectionUtils.java:713)
at org.apache.tomcat.util.IntrospectionUtils.setProperty(IntrospectionUtils.java:272)
at org.apache.tomcat.util.IntrospectionUtils.setProperty(IntrospectionUtils.java:261)
at org.apache.tomcat.util.digester.SetPropertiesRule.begin(SetPropertiesRule.java:215)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1282)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1543)
at org.apache.catalina.startup.Catalina.load(Catalina.java:554)
at org.apache.catalina.startup.Catalina.load(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:262)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:430)

回答1:


What do I need to include in Tomcat 7 to get javax.persistence working correctly ?

Not the Java EE SDK download from Oracle. It basically contains the Oracle Glassfish server. You seem to be misunderstanding what exactly Java EE is.

  • What exactly is Java EE?

I strongly recommend to undo all changes you made in Tomcat while trying to morph it into a Glassfish server. Or, better, restart from scratch.

You should be choosing a concrete JPA implementation and installing it instead. There are several:

  • Hibernate
  • EclipseLink
  • OpenJPA

Each comes with a download link and decent documentation. Hibernate is the most popular. EclipseLink is the reference implementation (and thus the one used under the covers in Glassfish). OpenJPA is just another one from the Apache Software Foundation. Ultimately it's matter of dropping the JAR file(s) of the concrete JPA implementation in /WEB-INF/lib of the webapp (and thus not Tomcat's /lib).



来源:https://stackoverflow.com/questions/10974183/what-do-i-need-to-include-in-tomcat-7-to-get-javax-persistence-working-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!