Maven pom.xml 常用打包配置

Posted 陈小兵

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Maven pom.xml 常用打包配置相关的知识,希望对你有一定的参考价值。

<build>
        <!-- 指定JAVA源文件目录 -->
        <sourceDirectory>src</sourceDirectory>
        <!-- 配置资源文件-->
        <resources>
            <resource>
                <directory>src</directory>
                <includes>
                    <include>*/*.xml</include>
                    <include>*.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <!-- 配置资源文件插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!-- 配置编译插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!-- 配置Jar打包插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <excludes>
                        <exclude>*/*.xml</exclude>
                        <exclude>*.properties</exclude>
                        <exclude>**/Test/*</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <!-- 配置Jar打包源文件插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <!--输出依赖的jar-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
</build>

 

以上是关于Maven pom.xml 常用打包配置的主要内容,如果未能解决你的问题,请参考以下文章

maven常用命令

maven中打包项目为war包的pom.xml配置

maven常用插件pom配置

maven打包项目

如何配置pom.xml用maven打包java工程

如何配置pom.xml用maven打包java工程