[英]Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Source must refer to an existing file
i want to use maven-jar-plugin to build diff classifier jars,like : 我想使用maven-jar-plugin来构建diff分类器jar,例如:
mvn deploy:deploy -P debug , classifier-demo-0.0.1-debug.jar deployed mvn 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:部署-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>
Goal: Repackage Repackage tries to repackage original artifact ie projectName.jar. 目标:重新包装重新包装尝试重新包装原始工件,即projectName.jar。 Which is outcome of default package phase of maven ie mvn package command output.
这是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. 当你运行mvn spring-boot:package时,projectName.jar不在那里。 that why it gives error Source must refer to an existing file
为什么它会给出错误Source必须引用现有文件
Solution: run command mvn clean package spring-boot:repackage 解决方案:运行命令mvn clean package spring-boot:repackage
i guess this is reason: 我想这就是原因:
this.project.getArtifact().getFile()
spring-boot-maven-plugin\\src\\main\\java\\org\\springframework\\boot\\maven\\RepackageMojo.java 弹簧引导Maven的插件的\\ src \\主\\ java的\\组织\\ springframework的\\启动\\行家\\ 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");
}
}
}
};
// ......
}
Actually, if you set Spring Boot Maven Plugin, you have included spring-boot:repackage into package. 实际上,如果你设置Spring Boot Maven插件,你已经将spring-boot:repackage包含在包中。 So just "mvn clean package" is enough, we don't need "mvn package spring-boot:repackage".
所以只需“mvn clean package”就够了,我们不需要“mvn package spring-boot:repackage”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.