【问题标题】:Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Source must refer to an existing file目标执行默认 org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Source must refer to an existing file
【发布时间】:2015-04-02 06:32:43
【问题描述】:

我想使用 maven-jar-plugin 来构建差异分类器 jar,例如:

mvn deploy:deploy -P debug , classifier-demo-0.0.1-debug.jar 部署

mvn deploy:deploy -P test , classifier-demo-0.0.1-test.jar 已部署。

但失败:

Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Source must refer to an existing file

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.3.RELEASE</version>
</parent>
<groupId>org.lenic</groupId>
<artifactId>classifier-demo</artifactId>
<version>0.0.1</version>
<properties>
    <java.version>1.7</java.version>
</properties>

<distributionManagement>
    <repository>
        <id>local-repo</id>
        <url>file://D:\repo</url>
    </repository>
</distributionManagement>

<profiles>
    <profile>
        <id>test</id>
        <properties>
            <classifier>test</classifier>
        </properties>
    </profile>
    <profile>
        <id>debug</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <classifier>debug</classifier>
        </properties>
    </profile>
</profiles>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <classifier>${classifier}</classifier>
            </configuration>
        </plugin>
    </plugins>
</build>

【问题讨论】:

  • 我认为 spring-boot-maven-plugin 忽略了 属性,找不到 classifier-demo-0.0.1-debug.jar ,它只检查 classifier-demo-0.0.1.jar 重新打包。
  • 我不确定,我猜

标签: java maven spring-boot


【解决方案1】:

目标:重新包装 Repackage 尝试重新打包原始工件,即 projectName.jar。这是 maven 的默认包阶段的结果,即 mvn package 命令输出。

当 Repackage 目标执行时,它会尝试查找 projectName.jar。

当您运行 mvn spring-boot:package 时 projectName.jar 不存在。 为什么它会给出错误Source must refer to an existing file

解决方案: 运行命令 mvn clean package spring-boot:repackage

【讨论】:

  • 我注意到当你说 mvn package 时,它​​完全跳过了 webapps 文件夹。有什么解决办法吗?
【解决方案2】:

我猜这是原因:

this.project.getArtifact().getFile()

spring-boot-maven-plugin\src\main\java\org\springframework\boot\maven\RepackageMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    // ......

    File source = this.project.getArtifact().getFile();
    File target = getTargetFile();
    Repackager repackager = new Repackager(source) {
        @Override
        protected String findMainMethod(JarFile source) throws IOException {
            long startTime = System.currentTimeMillis();
            try {
                return super.findMainMethod(source);
            }
            finally {
                long duration = System.currentTimeMillis() - startTime;
                if (duration > FIND_WARNING_TIMEOUT) {
                    getLog().warn(
                            "Searching for the main-class is taking some time, "
                                    + "consider using the mainClass configuration "
                                    + "parameter");
                }
            }
        }
    };
    // ......
}

【讨论】:

    【解决方案3】:

    实际上,如果你设置了 Spring Boot Maven Plugin,你已经将 spring-boot:repackage 包含在包中。所以只要“mvn clean package”就够了,我们不需要“mvn package spring-boot:repackage”。

    【讨论】:

    • 如果您想使用特定的 Spring 配置文件将其打包到 jar 中,并且仍然为本地开发保留“默认”配置文件,该怎么办?
    猜你喜欢
    • 2014-06-22
    • 2018-07-31
    • 2023-03-05
    • 1970-01-01
    • 2023-03-17
    • 2018-07-30
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多