Aspose cells error on Docker alpine jdk 17 image

Hi,
Aspose cells returns an error saving workbooks if executed on Docker image with amazoncorretto-17.0.12-alpine3.20 and alpine in general even with Fontconfig, freetype and all fonts installed.

Is there a way

  • to run java project
  • or to configure aspose
  • or to fix these containers

to avoid this problem?

Thanks

    java.lang.InternalError: java.lang.reflect.InvocationTargetException
	at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:87)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
	at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:75)
	at java.desktop/sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.java:137)
	at java.desktop/sun.java2d.SunGraphicsEnvironment.getAllFonts(SunGraphicsEnvironment.java:156)
	at java.desktop/sun.java2d.HeadlessGraphicsEnvironment.getAllFonts(HeadlessGraphicsEnvironment.java:76)
	at com.aspose.cells.b.a.b.c.a.ab.<clinit>(Unknown Source)
	at com.aspose.cells.b.a.b.q.<clinit>(Unknown Source)
	at com.aspose.cells.b.a.b.y.<init>(Unknown Source)
	at com.aspose.cells.b.a.b.y.<init>(Unknown Source)
	at com.aspose.cells.cvj.<clinit>(Unknown Source)
	at com.aspose.cells.cdw.<init>(Unknown Source)
	at com.aspose.cells.cdw.<init>(Unknown Source)
	at com.aspose.cells.cfh.a(Unknown Source)
	at com.aspose.cells.Shape.ar(Unknown Source)
	at com.aspose.cells.ane.a(Unknown Source)
	at com.aspose.cells.ane.a(Unknown Source)
	at com.aspose.cells.ane.<init>(Unknown Source)
	at com.aspose.cells.amw.a(Unknown Source)
	at com.aspose.cells.amr.a(Unknown Source)
	at com.aspose.cells.amx.b(Unknown Source)
	at com.aspose.cells.amx.a_(Unknown Source)
	at com.aspose.cells.Workbook.a(Unknown Source)
	at com.aspose.cells.Workbook.save(Unknown Source)
	... 30 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
	at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:85)
	... 65 common frames omitted
Caused by: java.lang.RuntimeException: Fontconfig head is null, check your fonts or fonts configuration
	at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1271)
	at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:224)
	at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:106)
	at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:706)
	at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:358)
	at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:315)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
	at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:315)
	at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
	at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
	... 71 common frames omitted

@federico.mameli

It seems you are encountering an issue with Aspose.Cells when running your Java project in a Docker container based on the Amazon Corretto JDK 17 Alpine image. The error message indicates a problem with font configuration, specifically that the Fontconfig head is null, which suggests that the fonts may not be properly configured or available in your Docker environment.

To resolve this issue, you can try the following steps:

  1. Ensure Fonts are Installed: Make sure that you have installed the necessary font packages in your Docker image. You can add the following lines to your Dockerfile to install fontconfig and some common fonts:

    RUN apk add --no-cache fontconfig ttf-dejavu
    
  2. Configure Fontconfig: After installing the fonts, you may need to configure Fontconfig. You can create a configuration file for Fontconfig if it doesn’t exist. This can be done by adding a custom configuration file in your Docker image.

  3. Use a Different Base Image: If the issue persists, consider using a different base image that is known to work well with Java applications and Aspose.Cells. For example, using a Debian or Ubuntu-based image might provide better compatibility with font rendering.

  4. Run in Headless Mode: Ensure that your Java application is running in headless mode, which is often necessary for server environments. You can set this by adding the following JVM argument:

    -Djava.awt.headless=true
    
  5. Test Locally: Before deploying to Docker, test your application locally to ensure that it works as expected. This can help isolate whether the issue is with the Docker environment or the application itself.

By following these steps, you should be able to configure your Docker container to work with Aspose.Cells without encountering the font-related errors. If you continue to experience issues, consider checking the Aspose documentation for additional guidance on running Aspose.Cells in Docker environments.

For more detailed instructions on running Aspose.Cells in Docker, you can refer to the official documentation here.

Sources:
[1]: How to Run Aspose.Cells for Java in Docker - Aspose Documentation

@federico.mameli,

If you continue to experience the issue after attempting the suggested steps/options, please provide your complete environment details, Docker file, code snippets, and template files (if applicable). We will evaluate your issue soon.