Implications of building a java program against the jars of one web container and deploying it in another

StackOverflow https://stackoverflow.com/questions/6819688

Question

What are the implications of building a java program against the jars of one web container (say Jetty) and running it in another (say Tomcat)?

I have an application which I run in Jetty durring development but which is deployed into a tomcat server for production (Why? because it seems easier to develop without having to run a whole tomcat server.)

Was it helpful?

Solution

You should compile against only the official Java EE API's for the level you target, for any non-developer builds. Preferably by a build engine. Preferably on a different operating system than you develop on.

For a web application this mean the appropriate servlet API as downloaded from Oracle. Similar for an enterprise application.

In my experience this is the best way to keep it straight.


Edit: Java EE SDK is available from http://www.oracle.com/technetwork/java/javaee/downloads/index.html. If you need an older version than Java EE 6, then follow the "Previous Releases" link.

OTHER TIPS

You can get issues such as MethodNotFoundError. You can usually resolve these by making sure versions of jars installed on the servers match.

you typically want to develop where you deploy. It might be slightly harder to develop with tomcat vs jetty, but you have identified a potential mess of a problem with jar conflicts, so doesn't it seem worth it to develop with tomcat, since you deploy to tomcat?

Also, typically the pain of developing against tomcat/your container of choice is mitigated by putting in the time to write a ant (or other) task that will deploy your code to your development container. The work cycle bemoes

1) Write new code
2) make sure tests pass
3) run your 'redeploy' script
4) poke around in the running instance

You probably want to do that.

Finally, in the spirit of loose coupling, you probably do not want to depend on a container-specific libraries if you can avoid it; only do that as an absolute last resort.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top