java 目标 org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Source must reference an existing file
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29406448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Source must refer to an existing file
提问by lenicliu
i want to use maven-jar-plugin to build diff classifier jars,like :
我想使用 maven-jar-plugin 来构建差异分类器 jar,例如:
mvn deploy:deploy -P debug , classifier-demo-0.0.1-debug.jar deployed
mvn deploy:deploy -P debug ,已部署classifier-demo-0.0.1-debug.jar
mvn deploy:deploy -P test , classifier-demo-0.0.1-test.jar deployed.
mvn deploy:deploy -P test ,已部署classifier-demo-0.0.1-test.jar。
but failure:
但失败:
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 :
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>
回答by Shailesh Kadam
Goal: Repackage Repackage tries to repackage original artifact i.e projectName.jar. Which is outcome of default package phase of maven i.e mvn packagecommand output.
目标:重新打包 Repackage 尝试重新打包原始工件,即 projectName.jar。这是 maven 的默认包阶段的结果,即mvn package命令输出。
When Repackage goal executes it tries to find projectName.jar.
当 Repackage 目标执行时,它会尝试查找 projectName.jar。
When you run mvn spring-boot:package at that time projectName.jar is not there. that why it gives error Source must refer to an existing file
当您运行 mvn spring-boot:package 时,projectName.jar 不存在。这就是为什么它给出错误源必须引用现有文件
Solution: run command mvn clean package spring-boot:repackage
解决方法:运行命令 mvn clean package spring-boot:repackage
回答by lenicliu
i guess this is reason:
我想这是原因:
this.project.getArtifact().getFile()
this.project.getArtifact().getFile()
spring-boot-maven-plugin\src\main\java\org\springframework\boot\maven\RepackageMojo.java
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");
}
}
}
};
// ......
}
回答by Sam
Actually, if you set Spring Boot Maven Plugin, you have included spring-boot:repackage into package. So just "mvn clean package" is enough, we don't need "mvn package spring-boot:repackage".
实际上,如果您设置了 Spring Boot Maven Plugin,则您已经将 spring-boot:repackage 包含在 package.json 中。所以只需要“mvn clean package”就足够了,我们不需要“mvn package spring-boot:repackage”。