2

I am developing simple JAX-WS webservice. I am creating WAR file using ANT build script. The file when deployed to Tomcat 7 server, throws following exception and there is deployment error as follows.

JAXB 2.1 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/D:/DreamSoln/Server/apache-tomcat-7.0.29/webapps/WebserviceDemo/WEB-INF/lib/jaxb-impl.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.2 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader.

I have JDK 1.6 installed, I tried endorsed mechanism i.e. I created lib/endorsed directory and copied jaxb-api.jar and jaxws-api.jar in it. But still it does not work.

Do I need to remove jaxb-api.jar and jaxws-api.jar from WEB-INF/lib of my web-app?

What else needs to be done?

informatik01
  • 16,038
  • 10
  • 74
  • 104
RickDavis
  • 2,276
  • 6
  • 25
  • 31

3 Answers3

2

I think that you are not endorsing correctly the tomcat lib. The folder lib/endorsed was used in previous version of tomcat (like Tomcat 5.5 if I remembered correctly) but in the new ones (Tomcat 6 and afterwards) the endorsed lib is usually at <TOMCAT_HOME>/endorsed (if it does not exist, you have to create it).

Actually, tomcat use the system property java.endorsed.dirs to define the endorsed folder location. So please check this value in your tomcat installation.

How to check this? Printing this property in any servlet/listener that you have in your application.

Example Using a context listener (inspired from this blog)

public class WebappLoadListener implements ServletContextListener {

    public void contextDestroyed(ServletContextEvent arg0) {
    }

    public void contextInitialized(ServletContextEvent arg0) {
        System.out.println("\n\n\n ENDORSED DIR: " +System.getProperty("java.endorsed.dirs"));      
    }
}

Hoping it helps,

ggarciao
  • 1,618
  • 16
  • 29
  • Thanks for your reply. I read the java.endorsed.dir property using method you suggested. But it gives me output as : [my-jre-home]/lib and not the [tomcat-home]/lib. – RickDavis Jul 24 '12 at 12:30
  • I observed that, its happening due to difference in JRE and Tomcat versions. I am using JDK 1.6 and Tomcat 7. I installed JDK 7 and it works fine with that. – RickDavis Jul 24 '12 at 12:32
  • When using the JDK 7 you are using the lasted version of JAXB (this is why is working). But if you still need to endorse your tomcat you need to put your libs in the `java.endorsed.dirs`. NOTE: Remember that you can change/set this property in the `catalina.sh`. – ggarciao Jul 24 '12 at 12:43
  • Would u advise how can i change and set these properties in Tomcat? and what version it should point to? – RickDavis Aug 01 '12 at 05:40
  • You need to set the value in the `JAVA_OPTS`. Please check this thread for more info: http://stackoverflow.com/questions/8424804/adding-java-opts-params-in-tomcat-6 – ggarciao Aug 01 '12 at 08:16
  • Regarding the JAXB version, if you make it work with Java 7, you should endorse your tomcat+java6 to use the JAXB version included in the Java7. Check this to know which version is included in each Java Release: http://jaxb.java.net/guide/Which_JAXB_RI_is_included_in_which_JDK_.html – ggarciao Aug 01 '12 at 08:31
0

Yes, you should remove these from the webapp once they are in the endorsed dir.

If you try the Java EE version of Tomcat, TomEE Plus, JAX-WS support is already integrated and JAXB 2.2 is in the endorsed dir.

David Blevins
  • 19,178
  • 3
  • 53
  • 68
0

Tomcat 7 does NOT support JAX-WS out of box. To enable JAX-WS on Tomcat you need

  1. to include at least "catalina-ws.jar" in Tomcat's lib (not necessarly under "endorsed"!).

"catalina-ws.jar" should be downloaded as "Tomcat extras", and it is not included in TC7's default download archive.

  1. Include the "JAX-WS RI" libs in your web applications lib.

just try google "The Next Milestone: JAX-WS Web Service on Tomcat and JBoss", you would find more information about this topic.

(However for a Java EE container like JBoss 7, all libs are there already. )

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140