maven 常用插件 拷贝依赖 拷贝jar包 查看属性 环境变量

1 maven编译后希望将生产的jar包拷贝到指定目录

 在pom中配置maven插件

maven-antrun-plugin
 <build >
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-lib-src-webapps</id>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <!-- <delete dir="src/main/webapp/WEB-INFb" />-->
                                <copy todir="F:\jar\libs">
                                    <fileset dir="${env.ACCOUNTINGDOCUMENT_JAVA_PATH}\fi-gl-accountingdocument-core\target">
                                        <include name="fi-gl-accountingdocument-core-1.0-SNAPSHOT.jar" />
                                    </fileset>
                                </copy>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>                    
                </executions>
            </plugin>
        </plugins>
    </build>

2 希望使用内置属性 ${properties.property} 方便项目协作

 但不清楚有哪些properties 没找到简单的查看properties的方法

 增加配置节点 执行validate 控制台会打印具体的properties

<execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <echoproperties />
                            </tasks>
                        </configuration>
</execution>

 

 

如 想将生成的jar包拷贝到F:\jar\libs

<build >
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-lib-src-webapps</id>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <!-- <delete dir="src/main/webapp/WEB-INFb" />-->
                                <copy todir="F:\jar\libs">
                                    <fileset dir="${project.build.directory}">
                                        <include name="${project.artifactId}-${project.version}.jar" />
                                    </fileset>
                                </copy>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
<!--                    <execution>-->
<!--                        <phase>validate</phase>-->
<!--                        <goals>-->
<!--                            <goal>run</goal>-->
<!--                        </goals>-->
<!--                        <configuration>-->
<!--                            <tasks>-->
<!--                                <echoproperties />-->
<!--                            </tasks>-->
<!--                        </configuration>-->
<!--                    </execution>-->
                </executions>
            </plugin>

        </plugins>


    </build>

 3 拷贝依赖到制定文件夹

includeGroupIds过滤拷贝的groupid
<properties>
        <project.targetDir>D:\jar</project.targetDir>
        <project.targetServerDir>\\localhost\c$\jar</project.targetServerDir>
    </properties>
    <build>
        <plugins>
 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>com.inspur.gs</includeGroupIds>
                            <outputDirectory>${project.targetDir}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

 

参考:

https://stackoverflow.com/questions/12317609/maven-overview-for-the-values-of-maven-properties

https://books.sonatype.com/mvnref-book/reference/resource-filtering-sect-properties.html

http://www.avajava.com/tutorials/lessons/how-do-i-display-the-value-of-a-property.html

  

 

posted @ 2019-09-03 09:21  wolbo  阅读(777)  评论(0编辑  收藏  举报