Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use external jars without adding them to the project

Tags:

java

tomcat

Hi In my project I have many many jars. Every time I change code and need to upload it to the server takes very long time, because I m adding the jars to the war to be deploy on tomcat. I m trying to put all the jars in the server, in some folder and to upload the rest of the project only, to speed the cycle. What will be the best way of doing that ?

I m using tomcat 8.5 also for production deployment without any build tool. I would like to set an ABSOLUTE path in the classpath but when doing that in my local machine it won't work after deployment to the unix server.

I never saw where or if I can set an absolute path for the jars (NOT OF THE LOCAL MACHINE)

Thanks in advance

like image 576
Eyal Rosenzvaig Avatar asked Feb 02 '17 15:02

Eyal Rosenzvaig


People also ask

Why can I not add external JARs in eclipse?

If your project builds with Java 9+ make sure you've selected Classpath (as shown here). You should also be able to add the JAR with right-click on the project > Build Path > Add External Archives....


1 Answers

You can read about this in Tomcat docs: Class Loader HOW-TO.

The most simple case and way - put these commonly used jars into $CATALINA_BASE/lib dir - they will be loaded by Tomcat class loader.

But, it doesn't seems to be very nice practice, as mentioned tutorials claims:

Normally, application classes should NOT be placed here.

Personally me, in practice purposes, I would ignore this hint and still place jars inside this folder. But if you want to be accurate, you could create separate path on server (or even inside CATALINA_BASE folder) and place jars there. After that you have to specify this path in $CATALINA_BASE/conf/catalina.propertiesfile in common.loader property:

common.loader="${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"
like image 157
Andremoniy Avatar answered Oct 04 '22 14:10

Andremoniy