-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
giving error 'Could not initialize class' in native image #95
Comments
Can you provide some example poi code on how you get this error? Keeping it as simple as possible? |
The sample code: https://github.com/cjbi/quarkus-poi-bug-report Gitpod online demo: https://gitpod.io/new#https://github.com/cjbi/quarkus-poi-bug-report |
@cjbi can you check if adding the following dependency works for you? <dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt</artifactId>
</dependency> |
Thank you for your answer. However, Adding this dependency to my project, it still doesn't seem to be working. |
Sounds like you need to add that font to your native distribution, see https://quarkus.io/guides/writing-native-applications-tips#including-resources |
agreed with @gastaldi your native image can't find the Font you are trying to use. Font font = workbook.createFont();
font.setFontName("黑体"); You need to include that font. Also note this issue with fonts: https://github.com/quarkiverse/quarkus-poi?tab=readme-ov-file#docker |
Thanks @gastaldi ,I removed the font, but it still didn't work. However,I found that when removed while (cellNo < cellLength) {
Cell cell = headRow.createCell(cellNo++);
// CellStyle style = workbook.createCellStyle();
// cell.setCellStyle(style);
cell.setCellValue("test name" + cellNo);
} Please look at the two lines of code with comments, when remove comments, it will cause an error.. |
Running my integration test now with that change |
i don't used macos,I found github actions can also reproduce: |
@cjbi if you are using Red Hat ubi-minimal did you see this note: https://github.com/quarkiverse/quarkus-poi?tab=readme-ov-file#docker It won't work in ubi-minimal without that script. For example here is one of mine that uses POI Native in UbiMinimal: |
I'm sorry bro @melloware , i don't notice the readme, but it still doesn't work after adding. |
I wonder if it’s a bug in Mandrel. Can you change to GraalVM CE just to check? |
@zakkak any hints? |
@gastaldi I using graalvm-ce from https://www.graalvm.org/latest/docs/getting-started/container-images/, it also can’t working. |
Trying this without Investigating further one can see that when building that native image a bunch of library files are placed next to the application:
Now if we move the binary to a different location, e.g.
So what happens here is that the application depends on those library files, but the libraries are not transferred to the docker image. This looks like a known issue quarkusio/quarkus#32576 (comment) that slept through the cracks and never got fixed (cc @Karm). Patching the reproducer with: diff --git a/.dockerignore b/.dockerignore
index 94810d0..c8324b0 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,5 +1,6 @@
*
!target/*-runner
!target/*-runner.jar
+!target/*.so
!target/lib/*
!target/quarkus-app/*
\ No newline at end of file
diff --git a/src/main/docker/Dockerfile.native b/src/main/docker/Dockerfile.native
index 8269f4f..45823b2 100644
--- a/src/main/docker/Dockerfile.native
+++ b/src/main/docker/Dockerfile.native
@@ -22,6 +22,8 @@ WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
&& chown 1001:root /work
+# Shared objects to be dynamically loaded at runtime as needed
+COPY --chown=1001:root target/*.so /work/
COPY --chown=1001:root target/*-runner /work/application
EXPOSE 8080
works-around the issue.
Thanks for bringing this to our attention! |
@zakkak Thanks for your help, i modified my code it's working fine. |
Thank you for the help @zakkak ! I'm going to close this now |
For the record, the upstream issue tracking this is quarkusio/quarkus#38412 |
in pom.xml I've:
io.quarkiverse.poi:quarkus-poi:2.0.5
when running on native image, an error will occur
when I'm running my project without native image it is running fine.
Output of java -version
21
Quarkus version or git rev
3.6.3
Build tool (ie. output of mvnw --version or gradlew --version)
Apache Maven 3.9.5
The text was updated successfully, but these errors were encountered: