POM中的多个依赖关系范围 [英] Multiple Dependency Scopes in POM

查看:119
本文介绍了POM中的多个依赖关系范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在POM中有一个依赖项,需要将其设置为提供",因此在编译时不包括该依赖项,但仍可以在我的项目中引用它.在运行测试时,我希望同一个依赖项的作用域为"test",因此不必手动将jar添加到我的类路径中.有办法做到这一点或取得类似结果吗?

I have a dependency in my POM that needs to be set to "provided" so it is not included at compilation, but it can still be referenced within my project. I would like the same dependency to have a scope of "test" when I go to run tests so I do not have to manually add the jar to my classpath. Is there a way to do this or achieve similar results?

这背后的原因是,我的JBOSS lib目录中提供了一些常用的jar,因此我想使用它们,并将它们的提供"范围保留在所建立的战争中.但是,当我从命令行运行JUnits时,我想使用存储库中的jar,而无需手动将其添加到我的类路径中.

Reasoning behind this is that I have some common jars that are provided in my JBOSS lib directory, so I want to use these and keep the "provided" scope of them for the war that is built. However, when I run JUnits from the command line, I want to use the jar from the repository without manually adding it to my classpath.

预先感谢

推荐答案

来自

已提供,这与编译非常相似,但是表明您期望使用JDK 或在运行时提供依赖项的容器.例如,当 为Java Enterprise Edition构建一个Web应用程序,您将 将对Servlet API和相关Java EE API的依赖关系设置为 提供范围,因为Web容器提供了这些类. 此 作用域仅在编译和测试类路径上可用,并且 不及物.

provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

我在maven 3.0.3中检查了这个对我有用.遇到相同的问题,我在编译和测试时需要具有servlet依赖关系,但由于没有随应用程序服务器发行版一起提供,因此没有在其中进行编译.

I checked this works for me in maven 3.0.3. Had the same issue that i needed to have a servlet dependency while compilation and test but not compiled in because it ships with the application server distribution.

这篇关于POM中的多个依赖关系范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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