引用 pom.xml 中的标签
Reference to the tags in pom.xml
如何或通常可以引用 java 中 pom.xml 的标签?您可以在 pom 中进行引用,例如:<outputDirectory>${project.build.directory}
.
但我想做这样的事情:
...
System.out.println(${project.version});
...
这可能吗?
在构建时您可以过滤一些资源文件,以便在运行时读取文件并获取您要查找的值:
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
或者如果它更复杂你可以使用汇编插件:
例如:
src/main/resources/info.属性
VERSION=${project.version}
并且在运行时:
Properties props = new Properties();
props.load(this.getClass().getResourceAsStream("info.properties"));
System.out.println(props.get("VERSION"));
如何或通常可以引用 java 中 pom.xml 的标签?您可以在 pom 中进行引用,例如:<outputDirectory>${project.build.directory}
.
但我想做这样的事情:
...
System.out.println(${project.version});
...
这可能吗?
在构建时您可以过滤一些资源文件,以便在运行时读取文件并获取您要查找的值:
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
或者如果它更复杂你可以使用汇编插件:
例如: src/main/resources/info.属性
VERSION=${project.version}
并且在运行时:
Properties props = new Properties();
props.load(this.getClass().getResourceAsStream("info.properties"));
System.out.println(props.get("VERSION"));