Maven重命名包含的文件

问题描述 投票:0回答:1

[构建jar时,我想包括一个文件,对其进行重命名并将其放置在jar中,但是Maven会将重命名的文件放置在目标文件夹中,而不是放置在jar中。如何重命名要包含在jar中的文件?

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.1</version>
            <executions>
                <execution>
                    <id>filter-resources</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <includes>
                                    <include>../rest-api/src/main/resources/xcs-${xcs.rest.api.version}.yaml</include><!-- File I want to rename -->
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.coderplus.maven.plugins</groupId>
            <artifactId>copy-rename-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <id>copy-and-rename-file</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>rename</goal>
                    </goals>
                    <configuration>
                        <sourceFile>../rest-api/src/main/resources/xcs-${xcs.rest.api.version}.yaml</sourceFile>
                        <destinationFile>${project.build.directory}/xcs.yaml</destinationFile><!-- Desired name -->
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>
maven jar maven-3 maven-plugin
1个回答
1
投票

您正在尝试使用错误的目标和执行ID复制并重命名该文件。试试这个:

<executions>
    <execution>
        <id>copy-rename</id>
        <phase>compile</phase>
        <goals>
            <goal>copy</goal>
        </goals>
...
© www.soinside.com 2019 - 2024. All rights reserved.