英文:
how to let "mvn compile" includes "provided" scope dependencies?
问题
我意识到当我在本地构建JAR文件时,“provided”范围的依赖未被包含,因此该JAR文件不可执行。
如何使“mvn compile”包含“provided”范围的依赖?
英文:
I realize that when I build the jar locally, the "provided" dependencies aren't get included, and so the jar is not executable.
how to let "mvn compile" includes "provided" scope dependencies?
答案1
得分: 2
将您的“provided”依赖项更改为“compile”依赖项。由于这是默认范围,在依赖项中删除范围标签。
引用文档,重点是:
- compile 这是默认范围,如果未指定范围,则使用此范围。编译依赖项在项目的所有类路径中都可用。
此外,这些依赖关系会传播到依赖项目。 - provided
- 这与“compile”非常类似,但表示您希望JDK或容器在运行时提供依赖关系。例如,在为Java Enterprise Edition构建Web应用程序时,您会将依赖关系设置为Servlet API和相关的Java EE API,
以范围“provided”设置,因为Web容器提供这些类。具有此范围的依赖项会添加到用于编译和测试的类路径中,但不会添加到运行时类路径中。
它不是可传递的。
简而言之:标记为“provided”的依赖关系不会包含在构建中,因为通过将其声明为提供的,您告诉Maven在构建中不必包含它,因为其他东西已经存在。
英文:
Change your "provided" dependencies to "compile" dependencies. Since it's the default scope, remove the scope tag in the dependency.
To quote the documentation, emphasis mine:
> - compile This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project.
> Furthermore, those dependencies are propagated to dependent projects.
> 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. A
> dependency with this scope is added to the classpath used for
> compilation and test, but not the runtime classpath. It is not
> transitive.
In short: a dependency that is marked as "provided" isn't included in your build because, by declaring it as provided, you are telling Maven that it does not have to include it in your build because something else is.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论