简体   繁体   English

在Java注释中使用Maven替换字符串

[英]Replacing Strings using Maven in Java Annotations

I am trying to replace a String in a Java annotation with variables from my pom.xml. 我正在尝试用来自pom.xml的变量替换Java注释中的字符串。

The pom.xml currently contains: pom.xml当前包含:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <parent.version>101</parent.version>
</properties>

I am trying to have the ${parent.version} replace in the annotation below to avoid having to replace the value multiple times as it is dependent on other versions 我试图在下面的注释中替换$ {parent.version},以避免不得不多次替换该值,因为它依赖于其他版本

public class MyClass {
  @Version { 
    parent = "${parent.version}"
  } 
  //more code to which cannot be moved elsewhere nor is really a template
}

I have looked at some replacement plugins, however they have either failed or require changing the source folder which feels to me unacceptable in sharing the project. 我看过一些替换插件,但是它们要么失败,要么需要更改源文件夹,这对我来说共享项目是不可接受的。

Is there such a method which can replace this ${parent.version} however not use a template? 有没有可以代替$ {parent.version}但不使用模板的方法?

根据您的示例,您可能想要使用templating-maven-plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM