Maven 无法读取属性文件
第三方财产Maven 无法读取属性文件,maven,version-control,pom.xml,Maven,Version Control,Pom.xml,第三方财产 xerces.version=1.0 我有这个属性文件,我想读取它的内容,但我无法读取 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>properties-maven-plugin</artifactId> <executions> <execution>
xerces.version=1.0
我有这个属性文件,我想读取它的内容,但我无法读取
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>3rdparty.properties</file>
<echo>foo is "${xerces.version}"</echo>
</files>
</configuration>
</execution>
</executions>
</plugin>
文件的路径正确吗?试用:
<files>
<file>${project.basedir}/3rdparty.properties</file>
</files>
${project.basedir}/3rdparty.properties
同时删除echo
语句
一旦解析pom,就会解析依赖项版本。它们不能由插件在运行时加载的属性设置,只能由已经存在的属性设置。所有生命周期阶段都在解决依赖项版本后执行。正确的方法是将属性移动到父pom并从中继承
有关相关问题,请参见此处:不,这不起作用,因为我前面已经尝试过,并且属性文件已经位于正确的位置,即basedir。这意味着您说我无法在外部文件中提供版本,如果我想访问,我无法访问。您可以通过父级pom传递它。它不能通过插件加载,因为所有生命周期阶段仅在解决依赖项版本后执行。请参阅editthen如果无法读取文件以访问它,那么properties maven-plugin的主要用途是什么。是否有其他方法从外部源访问属性文件。只需将版本写入依赖项的版本标记中即可。从属性重定向以使用该版本没有任何优势。
<files>
<file>${project.basedir}/3rdparty.properties</file>
</files>