将 Maven 与 Tomcat 一起使用时,将 3rd 方库放在哪里? [英] Where to put 3rd party libs when using Maven with Tomcat?

查看:57
本文介绍了将 Maven 与 Tomcat 一起使用时,将 3rd 方库放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Maven 的新手,我没有找到以下问题的正确答案.

I'm a new to Maven and I didn't find the proper answer to the following problem.

例如,我有我的项目所依赖的库,例如:log4j、connector j、servlet api、junit、struts 等.当我只使用 Tomcat 时,我可以将这些 jar 放到 %CATALINA_HOME%\lib 文件夹并使用它们.

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.

但是当 Maven 进来时,我可以为所有依赖项及其范围配置 pom.xml.

But as Maven comes in I can configure pom.xml for all dependencies and their scopes.

如果我这样做 - 我可以从 %CATALINA_HOME%\lib 文件夹中删除库吗?如果我可以,那么 Tomcat 怎么知道在哪里可以找到这个 3rd 方罐子?

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 ?

%CATALINA_HOME%\lib 文件夹中拥有 tomcat 原生库(tomcat-util、tomcat-juli、jasper 等)并在 中指定其他库是否是一个好习惯pom.xml ?

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 ?

推荐答案

仅仅拥有 tomcat-native libs 是一个好习惯吗?(tomcat-util、tomcat-juli、jasper 等)在 %CATALINA_HOME%\lib 文件夹中并在 pom.xml 中指定其他库?

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 ?

是的,这确实是一个很好的做法.这样,您的 Tomcat 安装将保持不变,您可以使用它来部署另一个 Web 应用程序(可能具有另一组依赖项,或在另一个版本中具有相同的依赖项).

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 将自动将依赖项放在最终 war 文件的 WEB-INF/lib 中,Tomcat(以及所有其他服务器)将在此目录中查找库.

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.

顺便说一下,我注意到您在帖子中提到了 servlet-api.此特定依赖项由 Tomcat 提供,这意味着您无需将其包含在最终战争中.使用 Maven,这意味着您需要添加 <scope> 为这个依赖提供了.

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.

这篇关于将 Maven 与 Tomcat 一起使用时,将 3rd 方库放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆