Java 读取pom.xml中的属性文件时出错
我有一个示例属性文件,如下所示 示例1.propertiesJava 读取pom.xml中的属性文件时出错,java,maven,pom.xml,maven-plugin,properties-file,Java,Maven,Pom.xml,Maven Plugin,Properties File,我有一个示例属性文件,如下所示 示例1.properties language=English site=www.google.com login=Login 我使用以下插件和目标将属性文件调用到pom.xml中 属性maven插件和 读取项目属性 我的pom.xml是 <plugin> <groupId>org.codehaus.mojo</groupId>
language=English
site=www.google.com
login=Login
我使用以下插件和目标将属性文件调用到pom.xml中
属性maven插件和
读取项目属性
我的pom.xml是
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/resources/sample.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
我试图访问代码中的pom.xml,如下所示
String site = System.getProperty("login");
有没有很好的理由让你走这么复杂的路..只要把属性文件int
src/test/resources
放进去,它们就可以从你的测试代码中使用了?你能展示一下测试代码吗?…属性文件是在参考资料部分下创建的,我知道它们也有其他类似于资源包的方式,或者在Pom.xml的属性中定义相同的方式,奇怪的是,通过加载属性文件以及如何将它们加载到iproperty部分,您知道这是如何发生的。有人能告诉我吗?@khmarbaise,这样“读取项目属性”的目标就不会将属性文件读取到pom.xml中,您能告诉我吗。@khmarbaise一旦将值提取到pom.xml中,我将在测试中使用下面的“String language=System.getProperty(site”);"
<properties>
</properties>
Cannot resolve symbol 'site' less... (Ctrl+F1)
Inspects a Maven model for resolution problems
String site = System.getProperty("login");