Error while reading the property file in pom.xml

2019-04-16 02:48发布

问题:

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");