在组装战争中包括Maven依赖项吗? [英] Include Maven dependencies in the assembly war?

查看:95
本文介绍了在组装战争中包括Maven依赖项吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用packaging=war创建一个程序集. 我需要包含一些jar,在我的战争(web-inf/lib)

中,这些jar被声明为pom.xml中的项目依赖项.

我该怎么做?

编辑于15/10- 我的项目创建了很少的程序集,其中一个程序集应该提供打包装的包装. WEB-INF下的war中需要包含一些jar文件,这些文件是项目的依赖项(已在pom.xml中声明). 如何包含它们或如何指出它们的路径到我的本地关系系统存储库路径?

解决方案

您能更精确吗?默认情况下,当在war项目上运行mvn clean install命令时,Maven 2将在WEB-INF/lib目录中包括所有依赖项,但范围在testprovided的依赖项除外.


如果您使用程序集创建战争文件,则您拥有assembly.xml文件,用于定义最终war文件的内容.在此文件中,您可以指定要包括的依赖项列表:

<assembly>
    ...
    <dependencySets>
        <dependencySet>
           <includes>
               <include>log4j:log4j</include>
               <include>commons-lang:commons-lang</include>
               ...
           </includes>
           <unpack>false</unpack>
           <outputDirectory>WEB-INF/lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

(在此示例中,我要求添加log4jcommons-lang依赖项). 对于每个依赖项,您需要指定groupId和artifactId.根据您在pom.xml文件中设置的依赖项列表,会自动检测到该版本.

I am creating an assembly with packaging=war. I need to include few of the jars, which have been declared as project dependencies in pom.xml in my war (web-inf/lib)

How can I do this?

Edited on 15/10- My project creates few assemblies, one of which is supposed to give packaging of type-war. Some jar files, which are dependencies for the project(and have been declared in pom.xml)need be included in war under WEB-INF. How can I include them or how can i point out their paths to my local nexus repository path?

解决方案

Can you be more precise? By default, when you run the mvn clean install command on a war project, Maven 2 will include all dependencies in WEB-INF/lib directories, excluding the ones with the scope test and provided.


If you create your war file using an assembly, then you have an assembly.xml file, which defines the content of your final war file. In this file, you can specify the list of dependencies you want to include:

<assembly>
    ...
    <dependencySets>
        <dependencySet>
           <includes>
               <include>log4j:log4j</include>
               <include>commons-lang:commons-lang</include>
               ...
           </includes>
           <unpack>false</unpack>
           <outputDirectory>WEB-INF/lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

(in this example, I asked to add log4j and commons-lang dependencies). For each dependency, you need to specify the groupId and the artifactId. The version is automatically detected regarding the list of dependencies you have set in your pom.xml file.

这篇关于在组装战争中包括Maven依赖项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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