码迷,mamicode.com
首页 > 其他好文 > 详细

利用maven-dependency-plugin插件使用及配置

时间:2017-08-12 17:17:12      阅读:709      评论:0      收藏:0      [点我收藏+]

标签:html   repos   des   log4   fine   ack   epo   pid   ase   

背景:

  1.需要某个特殊的 jar包,但是有不能直接通过maven依赖获取,或者说在其他环境的maven仓库内不存在,那么如何将我们所需要的jar包打入我们的生产jar包中。

  2.某个jar包内部包含的文件是我们所需要的,或者是我们希望将它提取出来放入指定的位置 ,那么除了复制粘贴,如何通过maven插件实现呢 

maven-dependency-plugin插件

  dependency  插件我们最常用到的是 dependency:copy  dependency:copy-dependencies  及dependency:unpack    dependency:unpack-dependencies 这四个,如果要实现上述的两种场景,我们需要的 是 第一个和第三个。

dependency:copy:takes a list of artifacts defined in the plugin configuration section and copies them to a specified location, renaming them or stripping the version if desired. This goal can resolve the artifacts from remote repositories if they don‘t exist in either the local repository or the reactor.(将一系列在此插件内列出的artifacts ,将他们copy到一个特殊的地方,重命名或者去除其版本信息。这个可以解决远程仓库存在但是本地仓库不存在的依赖问题)。

  其依赖配置如下:

            <!--dependency plugin test start-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>junit</groupId>
                                    <artifactId>junit</artifactId>
                                    <version>4.11</version>
                                    <outputDirectory>${project.build.directory}/lib/lib1</outputDirectory>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.slf4j</groupId>
                                    <artifactId>slf4j-log4j12</artifactId>
                                    <version>1.7.7</version>
                                    <outputDirectory>${project.build.directory}/lib/lib2</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

我们将两个指定的jar包junit slf4j-log4j12 分别输出到${project.build.directory}/lib/lib1  和${project.build.directory}/lib/lib2  目录下  即${project.basedir}/target/lib 目录下。

但是这样达到我们的 目的没有呢,这是没有的 我们希望将这些指定的  输出的文件打包到我们的war包中以方便在任何环境内都能正常运行。

大家是否还记得上篇博客:http://www.cnblogs.com/lianshan/p/7348093.html、

利用maven-assembly-plugin加载不同环境所需的配置文件的assembly.xml 文件定义的,fileSet定义的,我们可以将指定目录下的 文件输出到我们的war包结构中,好比这样

 

具体的详细配置可参考apache官网:http://maven.apache.org/components/plugins/maven-dependency-plugin/plugin-info.html

 

利用maven-dependency-plugin插件使用及配置

标签:html   repos   des   log4   fine   ack   epo   pid   ase   

原文地址:http://www.cnblogs.com/lianshan/p/7350614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!