首页 > 解决方案 > spring-boot-maven-plugin:2.0.0.RELEASE:repackage 失败:无法重命名

问题描述

我使用 command: mvn package来打包我的项目,pom.xml 如下:

<build>
        <defaultGoal>compile</defaultGoal>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass/>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

但它失败了,因为Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE:repackage failed: Unable to rename 'D:\Code\analysis\server\target\access_server-2.0.0.RELEASE.jar' to ' D:\Code\nalysis\server\target\access_server-2.0.0.RELEASE.jar.original'

此异常发生在 Windows 10 上,但在 centos 7 上没问题。

谁能帮我解决这个问题

标签: javamavenspring-boot

解决方案


尝试使用

mvn 清洁包

或者

mvn 干净安装

将 clean 与 package 或 install 一起使用将清除目标目录,这样同一个 jar 就不会在目标位置重叠。

package 将编译您的代码并将其打包。例如,如果你的 pom 说项目是一个 jar,它会在你打包时为你创建一个 jar,并将它放在目标目录的某个位置(默认情况下)。

install 将编译和打包,但它也会将包放在本地存储库中。这将使其他项目可以引用它并从您的本地存储库中获取它。


推荐阅读