[Maven]自动打包资源目录文件

前言

一般情况下,我们用到的资源文件(各种xml,properites,js文件等)都放在资源目录下面,利用maven打包时,maven能把这些资源文件打包到相应的目录里。

Maven内置变量说明

  • ${basedir} 项目根目录
  • ${project.build.directory} 构建目录,缺省为target
  • ${project.build.outputDirectory} 构建过程输出目录,缺省为target/classes
  • ${project.packaging} 打包类型,缺省为jar
  • ${project.xxx} 当前pom文件的任意节点的内容

下面我们开始配置Maven

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-resources-pluginartifactId>
                <version>2.5version>
                <executions>
                    <execution>
                        <id>copy-webappid>
                        <phase>process-sourcesphase>
                        <goals>
                            <goal>copy-resourcesgoal>
                        goals>
                        <configuration>
                            <outputDirectory>
                                ${basedir}/target/sino-biz-web
                            outputDirectory>
                            <resources>
                                <resource>
                                    <directory>
                                        ${basedir}/src/main/webapp
                                    directory>
                                    <includes>
                                        <include>**/**.*include>
                                    includes>
                                resource>
                            resources>
                        configuration>
                    execution>
                executions>
            plugin>
            
            
            <plugin>
                <artifactId>maven-resources-pluginartifactId>
                <version>2.5version>
                <executions>
                    <execution>
                        <id>copy-xmlsid>
                        <phase>process-sourcesphase>
                        <goals>
                            <goal>copy-resourcesgoal>
                        goals>
                        <configuration>
                            <outputDirectory>
                                ${basedir}/target/sino-biz-web/WEB-INF/classes
                            outputDirectory>
                            <resources>
                                <resource>
                                    <directory>
                                        ${basedir}/src/main/resources
                                    directory>
                                    <includes>
                                        <include>**/**.*include>
                                    includes>
                                resource>
                            resources>
                        configuration>
                    execution>
                executions>
            plugin>
        plugins>
    build>

通过以上配置即可实现自动打包资源文件到指定目录。

你可能感兴趣的:(Maven)