Error while reading the property file in pom.xml

徘徊边缘 提交于 2019-12-06 12:34:52

问题


I have a sample properties file as following.

sample.properties

language=English
site=www.google.com
login=Login

I am invoking the property file into my pom.xml using the following plugin and goal as

properties-maven-plugin and read-project-properties my pom.xml is

             <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>

But when I am accessing the same in the systemconfiguration I am unable to read them and getting an error

    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <systemPropertyVariables>
                            <language>${language}</language>
                            <site>${site}</site>
                            <login>${login}</login>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

Also the property tag as below is empty as the goal defined should read it and define it.

 <properties>
</properties>

And the Error as below

Cannot resolve symbol 'site' less... (Ctrl+F1) 
Inspects a Maven model for resolution problems

I am trying to access the pom.xml in the code as below.

String site = System.getProperty("login");

来源:https://stackoverflow.com/questions/51656393/error-while-reading-the-property-file-in-pom-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!