maven - 如何在 Maven 中管理编译时依赖

标签 maven maven-2 maven-3

尽量避免使用行话,以免被误解。

这是场景,我的项目需要一个 jar 才能编译(比方说 x.jar)。我的项目一旦编译就会转换成 WAR 文件,并部署在某个地方。
现在我希望 x.jar 只存在于我的项目中进行编译,并且它不应该打包(或部分)在 WAR 文件中。

我怎样才能在 Maven 中做到这一点?我应该使用依赖范围作为“提供”

最佳答案

你是对的,正如 Maven FAQs 中所述。 ,使用范围为provided ,

How do I prevent including JARs in WEB-INF/lib? I need a "compile only" scope! The scope you should use for this is provided. This indicates to Maven that the dependency will be provided at run time by its container or the JDK, for example.

Dependencies with this scope will not be passed on transitively, nor will they be bundled in an package such as a WAR, or included in the runtime classpath.

要快速尝试,您可以使用

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp

要生成“toy webapp”项目,请向您的项目添加依赖项并将其设置为 <scope>provided</scope> .

关于maven - 如何在 Maven 中管理编译时依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19499118/

相关文章:

java - Maven 项目的源文件的更改未反射(reflect)在 tomcat 中

java - Maven pom.xml 问题(缺少项目构建错误 "version")

java - 根据其他属性值在 Maven 中定义属性

maven-2 - IntelliJ IDEA : "Indexed Maven Repositories" list - how to add remote maven repository in this list?

java - 我如何从公司防火墙后面使用新的 JBoss Maven 存储库?

maven - 如何为插件的不同执行提供不同的属性集?

maven - Grails 支持新的 Maven 中心

maven - Mantis 集成到 Maven

java - 如何在Eclipse中制作war文件

java - 使用 Sonar 扫描仪扫描项目时出错