0

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)
Community
  • 1
  • 1
JHarnach
  • 3,944
  • 7
  • 43
  • 48
  • Hibernate looks to have an implementation. Since Tomcat doesn't have one, and I apparently can't find one in Glassfish, should I look to Hibernate for these files ? – JHarnach Jun 11 '12 at 03:24
  • Oh a servlet-api.jar is also available in the Tomcat lib folder, and does appear to have an copy of ServletException.class in it. – JHarnach Jun 11 '12 at 03:27

1 Answers1

6

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.

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:

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).

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC, my earlier experience with Tomcat led me to believe this was a matter of finding the right jars. I'll take this approach. – JHarnach Jun 11 '12 at 03:53
  • 1
    if you want somethine tomcat based TomEE might be worth a look: http://openejb.apache.org/apache-tomee.html – Korgen Jun 11 '12 at 11:43
  • Another non-Spring/non-TomEE variation is this openjpa+automanaged servlet wrapper (disclaimer: I did this for my projects) https://github.com/Murmur/ScopedEntityManager – Whome Sep 06 '14 at 15:45