我想使用maven-jar-plugin来构建diff分类器jar,例如:
mvn deploy:deploy -P debug,classifier-demo-0.0.1-debug.jar已部署
mvn 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>
答案 0 :(得分:8)
目标:重新包装 重新打包尝试重新打包原始工件,即projectName.jar。这是maven的默认包阶段的结果,即 mvn package 命令输出。
当Repackage目标执行时,它会尝试查找projectName.jar。
当你运行mvn spring-boot:package时,projectName.jar不在那里。 这就是为什么它会给出错误来源必须引用现有文件
解决方案: 运行命令 mvn clean package spring-boot:repackage
答案 1 :(得分:0)
我想这就是原因:
this.project.getArtifact().getFile()
弹簧引导行家-插件\ 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");
}
}
}
};
// ......
}
答案 2 :(得分:0)
实际上,如果你设置Spring Boot Maven插件,你已经将spring-boot:repackage包含在包中。所以只需“mvn clean package”就足够了,我们不需要“mvn package spring-boot:repackage”。