Quarkus 3 QR 生成使用 google.zxing 原生构建错误

问题描述 投票:0回答:1

我正在创建一个 Quarkus 3 应用程序来根据给定的 url 创建 QR 码。 在非本机构建中它工作正常,但是当以本机模式打包它时,它会给我一个关于某些丢失路径的错误。

Caused by: java.lang.UnsatisfiedLinkError: no awt in java.library.path at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryRelative(NativeLibrarySupport.java:136) at java.bas[email protected]/java.lang.ClassLoader.loadLibrary(ClassLoader.java:50)

这是 pom.xml:

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-awt</artifactId>
</dependency>
<dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>core</artifactId>
    <version>3.5.2</version>
</dependency>
<dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>javase</artifactId>
    <version>3.5.2</version>
</dependency>

这是我用来生成二维码的代码:

public class QRCodeGenerator {

    public static byte[] getQRCodeBytes(String text, int width, int height)
            throws WriterException, IOException {
        String imageFormat = "png"; // could be "gif", "tiff", "jpeg"
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix bitMatrix = qrCodeWriter.
                encode(text, BarcodeFormat.QR_CODE, width, height);
        ByteArrayOutputStream pngOutputStream =
                new ByteArrayOutputStream();
        MatrixToImageWriter.writeToStream(bitMatrix, imageFormat, pngOutputStream);
        return pngOutputStream.toByteArray();
    }

    public static String getQRCodeBase64(String text, int width, int height)
            throws WriterException, IOException {
        return encodeBase64String(getQRCodeBytes(text, width, height));
    }

    private static String encodeBase64String(byte[] binaryData) {
        return Base64.getEncoder().encodeToString(binaryData);
    }
}

我问是否有人有解决该错误的方法,或者有其他方法来处理二维码生成。 非常感谢!

编辑: 这是 dockerfile(我使用 Quarkus 默认的本机 Dockerfile,稍作修改):

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.8
WORKDIR /work/

COPY ./build_files/*-runner /work/application

EXPOSE 8080

ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]

这也是我用于构建此项目的 Jenkins 管道配置:

mkdir -p /var/xplorer/xplorer-label-dev/build_files
cp target/xplorer-label-*.jar /var/xplorer/xplorer-label-dev/build_files/xplorer-label.jar
cp target/xplorer-label-*-runner /var/xplorer/xplorer-label-dev/build_files/xplorer-label-runner
cp -f Dockerfile /var/xplorer/xplorer-label-dev/Dockerfile
cp -f docker-compose.yml /var/xplorer/xplorer-label-dev/docker-compose.yml
qr-code quarkus zxing quarkus-native
1个回答
0
投票

当我们执行本机构建时,我们看到一些

*.so
-文件也被列为工件:

$ ./mvnw --define native clean verify
...
Produced artifacts:
 /project/libawt.so (jdk_library)
 /project/libawt_headless.so (jdk_library)
 /project/libawt_xawt.so (jdk_library)
 /project/libfontmanager.so (jdk_library)
 /project/libjava.so (jdk_library_shim)
 /project/libjavajpeg.so (jdk_library)
 /project/libjvm.so (jdk_library_shim)
 /project/liblcms.so (jdk_library)
 /project/libmlib_image.so (jdk_library)
...

这些库也需要复制到容器中:

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.8
WORKDIR /work/

COPY ./build_files/*.so /work/application
COPY ./build_files/*-runner /work/application

EXPOSE 8080

ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]

我有一个非常相似的应用程序

github.com
。这是我的对应
containerfile
(
github.com
)
:

ARG DISTROLESS_IMAGE="quay.io/quarkus/quarkus-distroless-image:2.0@sha256:142abd361c081de7e4f7922362eb73e3d98f4ca060178688aeb4c969101e853b"

FROM ${DISTROLESS_IMAGE} as runner
ARG APP_DIR=/deployment
ARG UID=1001

USER root
WORKDIR ${APP_DIR}
COPY \
  --chmod=444 \
  target/*.so /lib/
COPY \
  --chmod=111 \
   target/*-runner ${APP_DIR}/application

ENV LANGUAGE='en_US:en'
USER ${UID}:${UID}
ENTRYPOINT [ "./application" ]
© www.soinside.com 2019 - 2024. All rights reserved.