Page 1 of 1

Java 1.5 NoClassDefFoundError

PostPosted: Fri Dec 14, 2012 5:24 am
by pinkmel
Hi, using docx4j 2.8.1 and has no problem in eclipse both compile and runtime. However, when deployed in Tomcat 5.5 with JRE1.5 external to eclipse, yet making sure all jars required are still in the deployed project\WEB-INF\lib folder, I am getting NoClassDefFoundError upon executing docx4j class to generate a docx from a fillable docx.

This is the exception that got thrown when the code to fill in a docx using docx4j is called:
Code: Select all
java.lang.NoClassDefFoundError: javax/xml/bind/ValidationEventHandler


This is the code that uses docx4j:
Code: Select all
public void generate() {

      try {

         WordprocessingMLPackage template = WordprocessingMLPackage.load(new ByteArrayInputStream(getTemplate().getContent()));
         List<Object> texts = getAllElementFromObject(template.getMainDocumentPart(), Text.class);

         Map<String, String> dataMap = createDataMap();

         for (Object text : texts) {

            Text textElement = (Text) text;
            String key = textElement.getValue();

            if (dataMap.containsKey(key)) {
               textElement.setValue(dataMap.get(key));
            }
         }
         fillInTables(template);
         saveDoc(template);

      } catch (Exception e) {
         throw new ApplicationRuntimeException(e);
      }
   }

Do you know what could be the problem? We do have javaee-api-5.0-1.jar under WEB-INF/lib that contains this ValidationEventHandler. Many thanks for any help.

Thanks,
Wendy

Re: NoClassDefFoundError at runtime

PostPosted: Fri Dec 14, 2012 7:36 am
by jason
Which JAXB implementation are you using?

You could try putting javax/xml/bind/ValidationEventHandler in an endorsed dir?

Re: NoClassDefFoundError at runtime

PostPosted: Fri Dec 14, 2012 10:46 am
by pinkmel
We don't use any JAXB and so we have only include those jaxb*.jars that docx4j said to include. Does the default jaxb that comes with j2ee jar or jre1.5 that we include not ok for docx4j?

The WEB-INF\lib folder contains the following jars, most of which are dependancies of docx4j:

activation.jar
antlr-2.7.7.jar
antlr-runtime-3.3.jar
avalon-framework-api-4.3.1.jar
avalon-framework-impl-4.3.1.jar
commons-beanutils.jar
commons-codec-1.3.jar
commons-collections.jar
commons-io-2.2.jar
commons-lang-2.4.jar
commons-logging-1.1.1.ar
docx4j-2.8.1.jar
edtftpj-1.4.1.jar
fop-1.0.jar
itext-2.1.7.jar
jakarta-regexp-1.2.jar
javaee-api-5.0.1.jar
jaxb-svg11-1.0.2.jar
jaxb-xmldsig-cor-1.0.0.jar
jaxb-xslfo-1.0.1.jar
jtds-1.2.jar
jxl.jar
log4j-1.2.15.jar
mail.jar
msbase.jar
mssqlserver.jar
msutil.jar
MultiRequest.jar
ostermillerutils_1_04_00.jar
poi-3.8.jar
poi-scratchpad-3.8.jar
serializer-2.7.1.jar
stringtemplate-3.2.1.jar
wmf2svg-0.9.0.jar
xalan-2.7.1.jar
xhtmlrenderer-1.0.0.jar
xml-apis-1.3.04.j14
xmlgraphics-commons-1.4.jar

Not sure if we are allowed to set the endorsed dir as it's shared server, i.e. many tomcat apps and we are just one of them.

Is it going to be okay if we are use jdk1.7 instead of 1.5 and tomcat 7 instead of tomcat 5?

Thank you so much.
Wendy

Wendy

Re: NoClassDefFoundError at runtime

PostPosted: Fri Dec 14, 2012 11:58 am
by jason
Java 5 does not come with JAXB, so you need to download and include a JAXB (typically the reference implementation).

Java 6 and Java 7 include JAXB.

You would be much better off with jdk1.7 and tomcat 7 instead of the older versions.

Re: Java 1.5 NoClassDefFoundError

PostPosted: Fri Dec 14, 2012 2:10 pm
by pinkmel
Thanks Jason. I will redeploy with the reference implementation of jaxb tomorrow and hopefully it will generate the docx.

Wendy

Re: Java 1.5 NoClassDefFoundError

PostPosted: Sat Dec 15, 2012 4:47 pm
by pinkmel
Well, included the latest JAXB reference implementation 2.2.6 (jaxb-api.jar, jaxb-impl.jar and jaxb-xjc.jar) but running into another error now.....trying to upgrade environment but it might take a while....do you happen to have an idea on what went wrong now.

java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class com.sun.istack.FinalArrayList)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1964)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:933)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1405)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

Thanks,
Wendy

Re: Java 1.5 NoClassDefFoundError

PostPosted: Sat Dec 15, 2012 5:47 pm
by jason
Sure, you are using a jar compiled for Java 1.6 on Java 1.5.

A few months ago a couple of people asked the Internet to identify the most recent version of JAXB compiled for Java 1.5. A quick Google ought to find those posts. If you can't, feel free to post again.

Re: Java 1.5 NoClassDefFoundError

PostPosted: Tue Dec 18, 2012 3:24 am
by pinkmel
Wow, i can't believed it's so hard to google and find the compatible JAXB jars for JDK1.5.

The RI website, for earlier version of JAXB, the binary only contains a Main.class file and no JARs.

I think I need the following 3 jars for JDK1.5:

jaxb-impl.jar
jaxb-api.jar
jaxb-xjc.jar


I tried to find them using findJars.com and got some but still getting runtime exception. If you have these jars for JDK1.5, can you please post me the link to download them. Thanks.

Wendy

Re: Java 1.5 NoClassDefFoundError

PostPosted: Wed Dec 19, 2012 7:58 am
by jason
Please see http://java.net/projects/jaxb/lists/use ... message/17 which says:

JDK 1.5 is in End Of Life period (http://java.sun.com/j2se/1.5/).

You can get last compatible released version 2_2_4-1:

http://jaxb.java.net/2.2.4-1/

OR checkout from SVN latest compatible not released version 2_2_4-4 and build it by yourself:

https://svn.java.net/svn/jaxb~version2/ ... xb-2_2_4u4


See also http://java.net/projects/jaxb/lists/use ... message/22