Resources are missing from JAR file after repackage with spring boot maven plugin
Asked Answered
C

0

6

My application uses some additional files which I have inside the resource folder. When I do the regular build with Maven and package my app into JAR, I can see all my resources in case I unzip this archive.

But when I create a docker image I use spring-boot-maven-plugin to make my JAR archive executable. For some reason my resources aren't being added to the new repacked JAR. Moreover I can not even unzip it because it is corrupted.

Here is the way I set the repackage goal in my pom.xml:

<id>prod</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>1.5.3.RELEASE</version>
                    <configuration>
                        <mainClass>ApplicationName</mainClass>
                        <executable>true</executable>
                        <arguments>
                            <argument>--spring.profiles.active=prod</argument>
                        </arguments>
                        <!--<addResources>true</addResources>-->
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                            <configuration>
                                <!--<includeSystemScope>true</includeSystemScope>-->
                                <!--<layout>JAR</layout>-->
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

I want to add that when I run my image in docker it works fine but all the needed resources are missing.

Has anyone run into the same problem? Or maybe you can suggest how to fix it.

Capitulary answered 14/6, 2017 at 7:6 Comment(3)
I think corrupted JAR is a clue. Create simple project and apply spring-boot-maven-plugin. If target JAR is corrupted, something is wrong with your environment. If target JAR is valid, add piece by piece your application until get corrupted JAR.Shepherd
@Shepherd as I already mentioned the target JAR is okay, but when I repack it ti make it executable it gets corrupted. So I guess the problem is in repackage part...Capitulary
@Shepherd The repackaged jar is actually working, spring is booting with the integrated tomcat server and working properly. The only issue is that the resources are not accessible anymore.Chemisorb

© 2022 - 2024 — McMap. All rights reserved.