[英]Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.0.2.RELEASE:repackage failed: Source must refer to an existing file
This is my first project using Spring (and I'm not too experienced with Maven either) and I get the error in the title when running mvn package
.这是我使用 Spring 的第一个项目(我对 Maven 也不太熟悉),运行mvn package
时标题中出现错误。
This is my 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>
<groupId>hu.infolaverage.europress.imageprovider</groupId>
<artifactId>imageprovider</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>hu.infolaverage.europress.imageprovider.App</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.11</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.11</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.7.11</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>2.7.11</version>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.0.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/libs-snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/libs-snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</project>
And here is the full error:这是完整的错误:
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building imageprovider 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ imageprovider ---
[INFO]
[INFO] --- spring-boot-maven-plugin:1.0.2.RELEASE:repackage (default) @ imageprovider ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.451 s
[INFO] Finished at: 2014-05-06T09:06:49+01:00
[INFO] Final Memory: 13M/167M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.0.2.RELEASE:repackage (default) on project imageprovider: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.0.2.RELEASE:repackage failed: Source must refer to an existing file -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.0.2.RELEASE:repackage (default) on project imageprovider: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.0.2.RELEASE:repackage failed: Source must refer to an existing file
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.0.2.RELEASE:repackage failed: Source must refer to an existing file
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:144)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: java.lang.IllegalArgumentException: Source must refer to an existing file
at org.springframework.boot.loader.tools.Repackager.<init>(Repackager.java:56)
at org.springframework.boot.maven.RepackageMojo$1.<init>(RepackageMojo.java:102)
at org.springframework.boot.maven.RepackageMojo.execute(RepackageMojo.java:102)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
... 20 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Same thing happens when I remove the version
and executions
from the spring-boot-maven-plugin
.当我从spring-boot-maven-plugin
中删除version
和executions
时,也会发生同样的事情。
在运行spring-boot:repackage
之前尝试mvn install
:
mvn clean install spring-boot:repackage
Ok, I found the error.好的,我发现了错误。 I needed to change the packaging
parameter to jar
from pom
.我需要将packaging
参数从pom
更改为jar
。 Also, the repositories
, pluginRepositories
, the maven-compiler-plugin
and the spring-boot-maven-plugin
's version
and executions
weren't needed.此外, pluginRepositories
repositories
、 pluginRepositories
、 maven-compiler-plugin
和spring-boot-maven-plugin
的version
和executions
。
Just adding my experience :只是添加我的经验:
After none of the suggested solutions worked.在所有建议的解决方案都不起作用之后。 I figured out there was some issue with the downloaded spring-boot-maven-plugin in the .m2 folder.我发现 .m2 文件夹中下载的 spring-boot-maven-plugin 存在一些问题。 Deleting the plugin and allowing the "mvn clean install" to re-download and build worked.删除插件并允许“mvn clean install”重新下载和构建工作。
The exact error message in my case was this one:在我的情况下,确切的错误消息是这样的:
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.14.RELEASE:repackage invalid entry size (expected 1 but got 0 bytes)无法执行目标 org.springframework.boot:spring-boot-maven-plugin:1.5.14.RELEASE:repackage invalid entry size (expected 1 but got 0 bytes)
I was about to create an empty clean Spring Boot project and wanted to build it, to see if everything was good.我正要创建一个空的干净的 Spring Boot 项目并想构建它,看看是否一切都很好。 I found out that error was caused by the presence of en empty application.properties file.我发现错误是由空的application.properties文件引起的。 It was created but there was no any text in it.它已创建,但其中没有任何文本。 After I added a property (example, server.port: 19999), the project was built successfully.添加属性后(例如server.port:19999),项目构建成功。
If you are using intelliJ community, nothing listed will work.如果您使用的是 intelliJ 社区,则列出的任何内容都不起作用。 I switched to Eclipse and was able to run a spring project with the default settings from start.spring.io with while making no changes to the POM file or any settings.我切换到 Eclipse 并且能够使用 start.spring.io 中的默认设置运行 spring 项目,同时不更改 POM 文件或任何设置。 It seems intelliJ community makes a confusing mess out of spring projects.似乎 intelliJ 社区在 Spring 项目中造成了混乱。
In short try another IDE before going through with any changes.简而言之,在进行任何更改之前尝试另一个 IDE。 The start.spring.io setup should work as its packaged. start.spring.io 设置应该像它的打包一样工作。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
If your project is multi-module, bear in mind where the app class is.如果您的项目是多模块的,请记住 app 类的位置。 I had to do 3 things to make this work:我必须做 3 件事才能完成这项工作:
As always when you do a significant change in your pom, from your IDE do a Maven > update project.与往常一样,当您对 pom 进行重大更改时,请从您的 IDE 中执行 Maven > 更新项目。
As suggested by other people:正如其他人所建议的:
\n\nmvn clean install spring-boot:repackage
It still did not work... from the parent pom of my app.它仍然不起作用......来自我的应用程序的父pom。 My app is moltimodule, with one of the modules having the Spring Application class.我的应用程序是 moltimodule,其中一个模块具有 Spring Application 类。 Only when I run the repackage goal from that module I get my fat jar properly generated, otherwise I am getting:只有当我从该模块运行重新打包目标时,我才能正确生成我的胖 jar,否则我会得到:
Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.1:repackage failed: Unable to find main class
because the build starts with the modules the one having the main class depend on, and, of course, they do not hold the main class of the app.因为构建从具有主类所依赖的模块开始,当然,它们不包含应用程序的主类。
I am still investigating why, because I want to have my project built in one shot as per the reactor dependency detection, rather than doing it in 2 shots, which apart from ugly is quite inconvenient for CI automation.我还在研究为什么,因为我希望我的项目按照反应堆依赖项检测一次性构建,而不是分两次构建,除了丑陋之外,对于 CI 自动化来说非常不方便。
For me, the trick was reinstalling all dependencies.对我来说,诀窍是重新安装所有依赖项。
This can be done in two ways:这可以通过两种方式完成:
mvn dependency:purge-local-repository
to delete all local dependencies使用mvn dependency:purge-local-repository
删除所有本地依赖项 Then, follow it up by a mvn clean install
to load all the dependencies again.然后,通过mvn clean install
再次加载所有依赖项。
For me it was API incompatibility exception.对我来说,这是 API 不兼容异常。 Since I did not specify the version in the plugin, the plugin was looking for the latest version which was not compatible, you have to specify the version explicitly for the plugin spring-boot-maven-plugin
由于我没有在插件中指定版本,插件正在寻找不兼容的最新版本,您必须为插件spring-boot-maven-plugin
明确指定版本
Refer to Unable to load the mojo 'repackage' in the plugin spring-boot-maven-plugin due to an API incompatibility 由于 API 不兼容,请参阅无法在插件 spring-boot-maven-plugin 中加载 mojo 'repackage'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.