Search code examples
spring-bootmavendockerfilegithub-actions

Sapjco3.jar dependency gives an error in Spring boot project: It is not allowed to rename or repackage the original archive "sapjco3.jar"


Our project repository was migrated to GitHub and we changed building an image from jib-maven-plugin to using a Dockerfile and building it with GitHub actions.

In the former process the Sapjco3.jar library was added by giving an extra classpath.

<extraDirectories>
    <paths>
        <path>${project.basedir}/../some-module-name/lib</path>
    </paths>
</extraDirectories>
<extraClasspath>/sap/*</extraClasspath>

Because the application is now build through a Dockerfile this plugin had to be removed. Instead of this the spring-boot-maven plugin is used to repackage the whole project into one jar.

For this reason it would not be possible to do the same.

How do I get this .jar library into the final repackaged jar's BOOT-INF/lib folder? It has to be this exact sapjco3.jar library because else it would give the error in the title.

Already tried:

  • strip version
  • custom layout
  • maven-assembly-plugin
  • maven-shade-plugin

I expect the project to run with the sapjco3.jar library.


Solution

  • I fixed it using the maven-jar-plugin to configure an extra Class-Path. The extra classpath is relative to where the jar resides. When buliding the docker image with a Dockerfile you can add the library to this relative path.

    The solution is thereby modifying the META-INF file.

    POM.xml

    <!-- Add classpath entry to the manifest -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Class-Path>lib/sap/sapjco3.jar</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    

    Dockerfile

    COPY ./{path-to-library}/lib/sap ./lib/sap