maven打包,实现将jar包中的路径,打到对应的目录下

时间:2021-07-27 09:16:27
如果你想通过pom.xml文件的配置实现的话,你可以这样
1、打jar包时过滤配置文件
<build>
<!-- 过滤配置文件 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*</exclude>
</excludes>
<filtering>true</filtering>
</resource>
</resources>
               <plugins>
                    ..............
                </plugins>
<build>

2、在plugins中添加插件
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <encoding>UTF-8</encoding>
                <outputDirectory>
                                                ${project.build.directory}
                                         </outputDirectory>   <!-- 表示把配置文件拷到和jar包同一个路径下 -->
                <resources>
                    <resource>
                        <directory>src/main/resources/</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>