Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Java utility project and multiple web apps

If I create a utility project and multiple dynamic web projects within Eclipse and set it up so that dynamic web projects depend on the utility project, I'm guessing that I will have to redeploy all the dynamic web projects to the server if at some point I make enhancements to the utility project. If I understand correctly, setting dependancies will package the utility classes into each dynamic web project's WEB-INF/lib folder thus creating multiple have copies of the utility jar/classes.

But is there a way to have one copy of the utility jar/classes deployed to my server and shared between my apps? I work for a company that has a Configuration Management procedure (red tape, paper work, no value added) so I'd rather not have to redeploy ALL my apps and go through the CM process everytime I make a change to my utility class. I'd like to be able to CM the utility and then have all my apps just start using the updated utility project.

like image 627
jeff Avatar asked Sep 24 '26 02:09

jeff


2 Answers

In Eclipse, reference the utility project in build path, but do not export it as Java EE module dependency. To share it among all webapps on the same server, just drop in server's classpath. It's unclear which one you're using, so I can't give a more detailed answer. In case of Tomcat it's the /lib folder. Alternatively you can also add its path to Tomcat's shared classpath as definied in catalina.properties. After updating, just restarting/redeploying should be sufficient to get the webapp(s) to pick the changes. Other servletcontainers/appservers offers similar possibilities. See also Tomcat Classloader HOW-TO.

like image 173
BalusC Avatar answered Sep 26 '26 16:09

BalusC


First of all from a governance perspective you should know what all uses that jar and what will be affected by a change to it.

If you could be impacting multiple projects, then it might be better to actually package it with the application, as you can control when you "upgrade" to the newest version of the jar on a per project/application basis.

If you want to update them all at the same time without redeploying them all, then it might be best to place the file in a spot that is accessable to your application server (a shared library directory).

Then set up your application to add that jar to its classpath. Now if you update the jar it affects all of them at once.

You still may need to bounce the applications or the server for the change to take affect (depends on the server).

like image 34
Chris Aldrich Avatar answered Sep 26 '26 16:09

Chris Aldrich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!