2

I want to run create an uber jar to create a docker image of that. I am using spring-boot-maven-plugin to create the uber jar.

My pom file looks like this :

    <plugins>
       <plugin>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-maven-plugin</artifactId>
           <configuration>
               <mainClass>MainClassName</mainClass>
               <layout>JAR</layout>
               <finalName>JARName</finalName>
           </configuration>
           <executions>
                <execution>
                      <goals>
                           <goal>repackage</goal>
                      </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-jar-plugin</artifactId>
        </plugin>

Command to run : mvn clean package

Error : [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.5.RELEASE:repackage (default) on project projectName: Execution default of goal o rg.springframework.boot:spring-boot-maven-plugin:2.0.5.RELEASE:repackage failed: Source must refer to an existing file, got C:\GIT\projectLocation\target\classes ->

1 Answers1

0

I just had the same problem

java.lang.IllegalArgumentException: Source must refer to an existing file, got C:\YourPath\YourProject\target\classes

You need to know the following:

With source file the plugin refers to the original war or jar file which should be repackaged. The position should be

YourPath\YourProject\target

So every reason why the war file is not in the specified path can lead to this error:

  • the folder is empty (call mvn clean install)

  • the location is different (in the pom.xml file it is possible to redefine all directories)

  • there is no war file generated in the first place (check pom.xml and its war/jar plugins etc)

  • In my case I called the plugin inside a maven profile. Part of this profile definition was an overwritten <artifact.classifier>:

    <properties>
      <artifact.classifier>someChangedArtifactName</artifact.classifier>
    </properties>
    

    So the resulting file was not project-name-version.war but project-name-version-artifact.classifier.war so the subsequent call of the spring-maven-plugin couldn't find it

Lonzak
  • 9,334
  • 5
  • 57
  • 88