Reputation: 4064
I'm a new to Maven and I didn't find the proper answer to the following problem.
For example I have libraries that my project depends on like: log4j, connector j, servlet api, junit, struts etc. When I'm using just Tomcat I can put this jars to %CATALINA_HOME%\lib
folder and use them.
But as Maven
comes in I can configure pom.xml
for all dependencies and their scopes.
If I do it - can I remove libs from %CATALINA_HOME%\lib
folder ? If I can then how Tomcat
knows where to find this 3rd party jars ?
And Is it a good practice just to have tomcat-native libs (tomcat-util, tomcat-juli, jasper etc) in %CATALINA_HOME%\lib
folder and specify other libs in pom.xml
?
Upvotes: 1
Views: 317
Reputation: 69440
If I do it - can I remove libs from %CATALINA_HOME%\lib folder ?
Yes.
If I can then how Tomcat knows where to find this 3rd party jars ?
The classloader knows, that it has to look in your war/WEB-INF/lib Directory
.
And Is it a good practice just to have tomcat-native libs (tomcat-util, tomcat-juli, jasper etc) in %CATALINA_HOME%\lib folder and specify other libs in pom.xml ?
Yes it is.
Upvotes: 1
Reputation: 137064
And Is it a good practice just to have tomcat-native libs (tomcat-util, tomcat-juli, jasper etc) in %CATALINA_HOME%\lib folder and specify other libs in pom.xml ?
Yes, this is indeed a very good practice. This way, your Tomcat installation is left unchanged and you can use it to deploy another webapp (that might have another set of dependencies, or the same dependency in another version).
Maven will automatically place the dependencies inside WEB-INF/lib
of your final war file and Tomcat (and every other server) will look in this directory for the librairies.
By the way, I noticed you mentioned the servlet-api in your post. This particular dependency is provided by Tomcat, which means you do not need to include it in your final war. With Maven, that means you need to add <scope>provided</scope>
to this dependency.
Upvotes: 1