JAX-WS Web Services on Tomcat 8 – JAX-WS Library Files Location?
<p>For a normal JSP web-app that provides web-services, where should the JAX-WS library jar files be placed?</p>

<pre><code>&lt;tomcat-home&gt;/lib
</code></pre>

<p>or</p>

<pre><code>&lt;web-app&gt;/WEB-INF/lib
</code></pre>

<p>and why?</p>

<p>In general, when are library files considered part of the container infrastructure or part of the web application?</p>

<p><strong>DETAILS</strong></p>

<p>I have implemented various JAX-WS web services following, among others, these guides:</p>

<p><a href="https://jax-ws.java.net/2.2.10/docs" rel="nofollow">https://jax-ws.java.net/2.2.10/docs</a></p>

<p><a href="https://jaxenter.com/creating-soap-web-services-using-jax-ws-117689.html" rel="nofollow">https://jaxenter.com/creating-soap-web-services-using-jax-ws-117689.html</a></p>

<p><a href="http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/" rel="nofollow">http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/</a></p>

<p><a href="http://examples.javacodegeeks.com/enterprise-java/jws/jax-ws-web-services-on-tomcat/" rel="nofollow">http://examples.javacodegeeks.com/enterprise-java/jws/jax-ws-web-services-on-tomcat/</a></p>

<p><a href="http://www.java2blog.com/2013/03/jaxws-webservice-deployement-on-tomcat.html" rel="nofollow">http://www.java2blog.com/2013/03/jaxws-webservice-deployement-on-tomcat.html</a></p>

<p>Whilst the above guides were useful, there are differences in terms of both the required JAX-WS library jar files and where the JAX-WS library jar files should reside.</p>

<p>By trial and error, for JDK 1.8, Tomcat 8.0.30 &amp; JAS-WS 2.2.10, this is the list of JAX-WS library jars that seem to be required:</p>

<pre><code>gmbal-api-only.jar
ha-api.jar
jaxb-core.jar
jaxb-impl.jar
jaxws-api.jar
jaxws-rt.jar
management-api.jar
policy.jar
stax-ex.jar
streambuffer.jar
</code></pre>

<p>I am aware that the JDK contains some of the JAX-WS classes but these seem to be meant for standalone Java apps
ie all of the above jar files seem to be needed to avoid a ClassNotFoundException etc.</p>

<p>I have read the <a href="http://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html" rel="nofollow">Tomcat 8 class-loader how-to</a></p>

<p>and appreciate that there is a parent-tree, hierarchal class loader and that jar files in:</p>

<pre><code>&lt;web-app&gt;/WEB-INF/lib
</code></pre>

<ul>
<li>are only available to that web app ie are hidden from other web apps</li>
<li>causes the app war file(s) to be bloated as each web app has it’s own copy</li>
</ul>

<p>and that jar files in:</p>

<pre><code>&lt;tomcat-home&gt;/lib
</code></pre>

<ul>
<li>are available to and shared by all web apps</li>
<li>forces all web apps to use the same version of the library</li>
<li>libraries must be inter web-app shareable ie no statics, thread-safe etc</li>
<li>enables lookup via a JNDI Resource Factory eg JDBC, mail etc</li>
<li>suppresses memory leaks for DriverManager eg JDBC</li>
</ul>

<p>The web services seem to work when the JAX-WS library jar files are in either location.</p>

<p>Looking at the <a href="https://jax-ws.java.net" rel="nofollow">Metro JAX-WS project</a>,
where the JAX-WS library jars must be downloaded from, for now, I have put these into &lt;tomcat-home>/lib as that is consistent with the ‘install’ option in the ant file.</p>

<p>As a general rule, I try not to pollute the web-container / app-server with unnecessary library jar files where possible as this can lead to conflicts for other web-apps that have to use a specific version of a required library.</p>

<p>Thanks for reading.</p>