尽量避免使用行话,以免被误解。
这是场景,我的项目需要一个 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/