53

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.

This is my 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.

r1pp3rj4ck
  • 1,437
  • 2
  • 10
  • 23

10 Answers10

91

Try mvn install before running spring-boot:repackage:

mvn clean install spring-boot:repackage
Dimitris
  • 3,975
  • 5
  • 25
  • 27
  • 19
    Well, actually that worked for me. I used `mvn spring-boot:repackage` and got `Source must refer to an existing file`. Using `mvn clean install spring-boot:repackage` made it work. – sjngm Jun 06 '14 at 18:22
  • 9
    `mvn clean install spring-boot:repackage` also worked for me. – calvin Nov 16 '14 at 02:10
  • 1
    @sjngm your answer was definitely the best one. – joninx Jan 25 '17 at 11:52
  • @snjgm your comment should be the answer, and this worked for me, thanks! – alturium Mar 15 '18 at 14:13
  • 5
    you can also just do 'package' before hand instead of install... `mvn clean package spring-boot:repackage` – harmanjd Nov 16 '18 at 16:33
23

Ok, I found the error. I needed to change the packaging parameter to jar from pom. Also, the repositories, pluginRepositories, the maven-compiler-plugin and the spring-boot-maven-plugin's version and executions weren't needed.

r1pp3rj4ck
  • 1,437
  • 2
  • 10
  • 23
  • 5
    You're welcome, happy to help others who run into the same issues as I :) don't like to be DenverCoder9 :D – r1pp3rj4ck May 08 '14 at 07:09
4

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. Deleting the plugin and allowing the "mvn clean install" to re-download and build worked.

programmer
  • 49
  • 1
  • 2
  • 1
    Yes .. worked with me .. manually delete all the files in .`m2\repository` folder and then run `mvn -clean install` – Ahmed Nabil Aug 13 '18 at 06:25
1

If your project is multi-module, bear in mind where the app class is. I had to do 3 things to make this work:

  1. As always when you do a significant change in your pom, from your IDE do a Maven > update project.

  2. As suggested by other people:

    mvn clean install spring-boot:repackage
    
    
  3. It still did not work... from the parent pom of my app. My app is moltimodule, with one of the modules having the Spring Application class. Only when I run the repackage goal from that module I get my fat jar properly generated, otherwise I am getting:

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.

WinterBoot
  • 399
  • 1
  • 5
  • 15
  • And here is the hint for my issue 3 above: https://stackoverflow.com/questions/57187588/spring-boot-multi-module-maven-project-repackage-failed – WinterBoot Feb 19 '21 at 00:33
1

For me, the trick was reinstalling all dependencies.

This can be done in two ways:

  • using mvn dependency:purge-local-repository to delete all local dependencies
  • just deleting everything in the m2/repository folder, I suggest you use the mvn command.

Then, follow it up by a mvn clean install to load all the dependencies again.

Alex
  • 729
  • 2
  • 10
  • 24
maixnor
  • 11
  • 4
0

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)

I was about to create an empty clean Spring Boot project and wanted to build it, to see if everything was good. I found out that error was caused by the presence of en empty application.properties file. 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.

user07
  • 319
  • 2
  • 8
0

For me it was API incompatibility exception. 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

Refer to Unable to load the mojo ‘repackage’ in the plugin spring-boot-maven-plugin due to an API incompatibility

Reema
  • 70
  • 4
-1

I added to the pom.xml this configuration

<plugins>
 <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
      <skip>true</skip>
    </configuration>
 </plugin>
.
.
.
</plugins>

Source

bgarcial
  • 2,915
  • 10
  • 56
  • 123
-2

If you are using intelliJ community, nothing listed will work. 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. It seems intelliJ community makes a confusing mess out of spring projects.

In short try another IDE before going through with any changes. The start.spring.io setup should work as its packaged.

ChillieCode
  • 139
  • 1
  • 8
-3
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>