GraalVM in docker : Fatal error reported via JNI: Could not allocate set properties

142 Views Asked by At

I am trying to containerize my spring application with graalVM, but when the application is containerized, I cannot generate a PDF in my application. The API works as long as I don't generate pdf.

When my application runs locally, the PDF is generated. When my application is compiled natively and execute, the PDF is generated. When my application is compiled from a containerized environment, for example the image container-registry.oracle.com/graalvm/jdk:17, when I try to generate a pdf, the pdf will not be generated, and I have this error :

Fatal error reported via JNI: Could not allocate set properties

stacktrace: first second

In my spring application I use a library to generate PDFs: openhtml, version 1.0.10

For native compilation, I use the mvn -Pnative native:compile command, although mvn package -Pnative works too. These commands when executed locally generate a target folder, with an app.exe file inside allowing me to launch my native application When these commands are executed from a container, it is an app file, without .exe extension

Here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.6</version>
        <relativePath/>
    </parent>
    <groupId>com.bouvet</groupId>
    <artifactId>location-manager</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>location-manager</name>
    <description>Location Manager</description>

    <properties>
        <java.version>17</java.version>
        <openhtml.version>1.0.10</openhtml.version>
        <start-class>com.bouvet.locationmanager.LocationManagerApplication</start-class>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.librepdf</groupId>
            <artifactId>openpdf</artifactId>
            <version>1.3.30</version>
        </dependency>

        <dependency>
            <groupId>com.github.librepdf</groupId>
            <artifactId>pdf-toolbox</artifactId>
            <version>1.3.30</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        
        <dependency>
            <groupId>com.openhtmltopdf</groupId>
            <artifactId>openhtmltopdf-core</artifactId>
            <version>${openhtml.version}</version>
        </dependency>

        <dependency>
            <groupId>com.openhtmltopdf</groupId>
            <artifactId>openhtmltopdf-pdfbox</artifactId>
            <version>${openhtml.version}</version>
        </dependency>

        <dependency>
            <groupId>com.openhtmltopdf</groupId>
            <artifactId>openhtmltopdf-java2d</artifactId>
            <version>${openhtml.version}</version>
        </dependency>

        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <image>
                        <buildpacks>
                            <buildpack>gcr.io/paketo-buildpacks/graalvm</buildpack>
                            <buildpack>gcr.io/paketo-buildpacks/java-native-image</buildpack>
                        </buildpacks>
                        <env>
                            <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
                        </env>
                    </image>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>native</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>0.9.28</version>
                        <extensions>true</extensions>
                        <configuration>
                            <imageName>app</imageName>
                            <mainClass>com.bouvet.locationmanager.LocationManagerApplication</mainClass>
                            <verbose>true</verbose>
                        </configuration>
                        <executions>
                            <execution>
                                <id>build-native</id>
                                <configuration>
                                    <buildArgs>
                                        <arg>--static</arg>
                                        <arg>--no-fallback</arg>
                                        <arg>-H:IncludeResources=".*"</arg>
                                        <arg>-H:ConfigurationFileDirectories=META-INF/native-image/</arg>
                                        <arg>-H:+StaticExecutableWithDynamicLibC</arg>
                                        <arg>-H:+ReportExceptionStackTraces</arg>
                                    </buildArgs>
                                </configuration>
                                <phase>package</phase>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <classifier>exec</classifier>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Here is my Dockerfile:

FROM container-registry.oracle.com/graalvm/native-image:17-ol8
WORKDIR /build
COPY . /build
RUN rm -rf /build/target
RUN sed -i -e 's/\r$//' mvnw
RUN ./mvnw -Pnative native:compile
EXPOSE 80
ENV SERVER_PORT=80
ENTRYPOINT ["/build/target/app"]

To be compliant with librairies, i have already generate files with an agent with this command :

java -agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image -jar location-manager-0.0.1-SNAPSHOT.jar

Without this files, it is impossible to generate PDF in local environnement: META-INF

I am on a Windows 11 environment

native-image --version

native-image 21.0.1 2023-10-17 GraalVM Runtime Environment Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19) Oracle GraalVM VM Substrate 21.0.1+12.1 (build 21.0.1+12, serial gc, compressed references)

java --version

java version "21.0.1" 2023-10-17 Java(TM) SE Runtime Environment Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19) Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19, mixed mode, sharing)

Does anyone have any leads please ?

I have try this images :

  • ghcr.io/graalvm/graalvm-ce:ol8-java17-22.3.3
  • ghcr.io/graalvm/native-image:ol9-java17
  • ghcr.io/graalvm/jdk-community:17-ol9
  • ubuntu:jammy
  • container-registry.oracle.com/graalvm/native-image:17-ol8
  • container-registry.oracle.com/graalvm/native-image:21-ol8
  • container-registry.oracle.com/graalvm/jdk:17
  • scratch
0

There are 0 best solutions below