Maven在编译时获取属性 [英] maven get properties at compile time

查看:76
本文介绍了Maven在编译时获取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编译时如何在源文件中获取Maven属性

How can we get Maven properties in source file at compile time

pom.xml

<artifactId>myApp</artifactId>
<version>1.0.0</version>

Main.java

public class Main {
  private static final String artifactId = "project.artifactId";
  private static final String version = "project.version";
}

有可能在课堂上硬鳕鱼吗?

is it possible to hard cod in class?

推荐答案

您可以使用maven属性在generate-src目录中创建Java源文件,并通过构建助手maven插件将其附加到源文件夹列表中.

You can use maven property to create java source file in generate-src directory and attach it via build helper maven plugin to the list of source folders.

您将控制Java文件的内容.

You will control the contents of java file.

创建源Java文件的一种方法是使用带有内联的groovy maven插件.

One way to create source java file is to use groovy maven plugin with inlining.

这篇关于Maven在编译时获取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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