Skip to content

How to set up Apache Tomcat to integrate openstack4j

Vinod Borole edited this page Mar 28, 2016 · 3 revisions

A very likely to be successful solution will be explained below, step-by-step. It will be explained in a Non-Maven way and using the openstack-2.11-withdeps release (as it contains all the dependencies needed); but I am sure it will also be useful for Maven users too, as the only thing they will have to do is to configure their project setup file correctly.

Why am I experiencing issues?

As openstack4j requires runtime dependencies, you might be experiencing some issues when trying to integrate it to a project that needs Apache Tomcat to run. It is likely that most of these issues you are having are caused by dependency conflicts, as openstack4j will not be working if you are not using the correct dependencies release version or you are using different releases of the same dependency at the same time, inside the same project.

It is possible, for example, that you might be using a Jersey or Jackson release that is not compatible with this Openstack client. And it is also possible too that, once you've updated all of your dependencies that openstack4j needs (or deleted all of them and integrated openstack-2.11-withdeps in your project), your Apache Tomcat still crashes! That could be perfectly possible if you left something inside your project set up in the old dependencies way.

Anyway, if you have experienced any of these issues or not (because you have not set up your project with openstack4j yet), please follow the steps below.

How to set up Apache Tomcat

So, from now on, all you need to do is the following:

Download and integrate openstack4j in your project

  1. Download openstack-2.11-withdeps from here.
  2. Once you have downloaded the file, copy it to your WEB-INF/lib directory inside your project.

Download and set up Jersey: JAX-RS 2.0 RI bundle

As openstack4j needs Jersey 2.0 to work correcty, you will need to use and set up your whole project in the 2.0 way.

  1. Download Jersey 2.0 : JAX-RS 2.0 RI bundle from here. This zip bundle file contains the JAX-RS 2.0 API jar, all the core Jersey module jar files as well as all the required 3rd-party Jersey 2.0 dependencies.
  2. Once your download is complete, extract the zip file and do the following:
  • Copy all the jar files inside the /ext directory, into your Apache Tomcat's /lib directory.
  • Copy the following jar files inside the /ext directory, into your project's WEB-INF/lib directory:
    • hk2-api-2.4.0-b34
    • hk2-locator-2.4.0-b34
    • hk2-utils-2.4.0-b34
  • Copy all the jar files inside /lib directory, into your project's WEB-INF/lib directory.

Note: We will not need the javax.ws.rs-api-2.0.1.jar file found at the zip's /api directory, as it is already inside the openstack-2.11-withdeps jar file with the rest of dependencies.

Set up your web.xml in the 'JAX-RS 2.0' way

Finally, all we need is to have everything else set up correctly. Make sure you modify as well your project's web.xml file in the 2.0 way, if needed. If you were using an older Jersey release before you integrated openstack4j into your project, you must change your servlet-class and your init-param param-name parameters (at least) to have them in the new way:

<servlet>
	<servlet-name>JAX-RS Rest Service</servlet-name>
	<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
	<init-param>
		<param-name>jersey.config.server.provider.packages</param-name>
		<param-value>es.stw.api</param-value>
	</init-param>
	<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
	<servlet-name>JAX-RS Rest Service</servlet-name>
	<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

Observations

This solution works fine and has been validated by different users who had to integrate openstack4j to their projects that needed Apache Tomcat to run. But, of course, that does not mean or ensures this solution will work 100% for everyone.