如何在 quarkus 中特别获取应用程序的版本(由 pom.xml 中的标签版本定义)? [英] How can I get the version of the application (defined by tag version in pom.xml) in quarkus specially?

查看:58
本文介绍了如何在 quarkus 中特别获取应用程序的版本(由 pom.xml 中的标签版本定义)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个普通的 Java EE 应用程序转移到 quarkus.io.在 Java EE 中,我有一个属性文件version=${project.version} 并在 JAX RS 端点中读取此文件.这非常有效.

I moved from a plain Java EE application to quarkus.io. In Java EE I had the a properties file with version=${project.version} and reeading this file in an JAX RS endpoint. This worked very well.

@GET
public Response getVersion() throws IOException {
    InputStream in = getClass().getClassLoader().getResourceAsStream("buildInfo.properties");
    if (in == null) {
        return Response.noContent().build();
    }
    Properties props = new Properties();
    props.load(in);
    JsonObjectBuilder propertiesBuilder = Json.createObjectBuilder();
    props.forEach((key, value) -> propertiesBuilder.add(key.toString(), value.toString()));
    return Response.ok(propertiesBuilder.build()).build();
}

现在我正在使用 quarkus 和 MicroProfile,我想知道是否有更好的方法.

Now that I am using quarkus and MicroProfile, I wonder if there is a better approach.

我使用 MicroProfile 中的 ConfigProperty 设置进行了尝试.

I tried it with the ConfigProperty setup from MicroProfile.

@ConfigProperty(name = "version")
public String version;

但我收到以下错误:

未找到属性 project.version.

这是我的 pom 的构建部分.

Here is my build section of my pom.

<build>
    <finalName>quarkus</finalName>
    <plugins>
        <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>1.0.0.CR2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>build</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${surefire-plugin.version}</version>
            <configuration>
                <systemProperties>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                </systemProperties>
            </configuration>
        </plugin>
    </plugins>
</build>

有什么解决方案/更好的方法吗?

Is there any solution / better approach?

推荐答案

尝试


@ConfigProperty(name = "quarkus.application.version")
String version;

您也可以从清单中读取实施版本.

Also you can read the Implementation-Version from the manifest.

这篇关于如何在 quarkus 中特别获取应用程序的版本(由 pom.xml 中的标签版本定义)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆