0

I have a project that contains a file extra-config.properties in src/main/resources which I reference in my code using:

getClass().getClassLoader().getResourceAsStream("extra-config.properties"))

This works perfectly in JVM mode, but when I build a native image the file is not accessible, because it is not included in the binary.

How can I instruct Quarkus to include it?

4

1 回答 1

1

在构建原生二进制文件时,GraalVM 默认不包含镜像中的类路径资源。相反,您需要按照此处-H:IncludeResources所述指定。

在 Quarkus 中执行此操作的方法是配置quarkus-maven-plugin插件以添加additionalBuildArgs属性。配置如下所示:

                <plugin>
                    <groupId>io.quarkus</groupId>
                    <artifactId>quarkus-maven-plugin</artifactId>
                    <version>${quarkus.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>native-image</goal>
                            </goals>
                            <configuration>
                                <additionalBuildArgs>-H:IncludeResources=extra-properties.json</additionalBuildArgs>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
于 2019-06-07T20:39:58.320 回答