XML : Reading from POM.xml file is always null (Maven, java)

I want read from pom.xml file in my java app.

I read a lot of article about this problem, but solution not work.

I make test class for testing:

  public class test {      public static void main(String[] args) {          System.out.println(System.getProperty("databse.username"));      }  }    

pom.xml file:

  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">      <!-- I HIDE PERSONAL DATA -->        <properties>          <junit.version>3.8.1</junit.version>          <mysql.connector.version>5.1.34</mysql.connector.version>          <commons.lang3.version>3.3.2</commons.lang3.version>          <database.username>nobodyTest</database.username>          </properties>        <dependencies>            <dependency>              <groupId>junit</groupId>              <artifactId>junit</artifactId>              <version>${junit.version}</version>              <scope>test</scope>          </dependency>            <dependency>              <groupId>mysql</groupId>              <artifactId>mysql-connector-java</artifactId>              <version>${mysql.connector.version}</version>          </dependency>            <dependency>              <groupId>org.apache.commons</groupId>              <artifactId>commons-lang3</artifactId>              <version>${commons.lang3.version}</version>          </dependency>              <!-- Servlet Stuff -->            <dependency>              <groupId>javax.servlet</groupId>              <artifactId>javax.servlet-api</artifactId>              <version>3.1.0</version>              <scope>provided</scope>          </dependency>            <dependency>              <groupId>javax.servlet</groupId>              <artifactId>jstl</artifactId>              <version>1.2</version>              <scope>provided</scope>          </dependency>            <!-- JPA - Hibernate stuff -->            <dependency>              <groupId>org.hibernate.javax.persistence</groupId>              <artifactId>hibernate-jpa-2.1-api</artifactId>              <version>1.0.0.Final</version>          </dependency>            <dependency>              <groupId>org.hibernate</groupId>              <artifactId>hibernate-entitymanager</artifactId>              <version>4.3.8.Final</version>          </dependency>            <dependency>              <groupId>org.hibernate</groupId>              <artifactId>hibernate-c3p0</artifactId>              <version>3.6.3.Final</version>          </dependency>            <dependency>              <groupId>javax.mail</groupId>              <artifactId>mail</artifactId>              <version>1.5.0-b01</version>          </dependency>          </dependencies>        <build>          <plugins>              <plugin>                  <groupId>org.apache.maven.plugins</groupId>                  <artifactId>maven-compiler-plugin</artifactId>                  <version>3.3</version>                  <configuration>                      <source>1.7</source>                      <target>1.7</target>                  </configuration>              </plugin>                <plugin>                  <groupId>org.eclipse.jetty</groupId>                  <artifactId>jetty-maven-plugin</artifactId>                  <version>9.2.11.v20150529</version>                  <configuration>                      <scanIntervalSeconds>1</scanIntervalSeconds>                      <webApp>                          <contextPath>/</contextPath>                      </webApp>                  </configuration>              </plugin>            </plugins>      </build>  </project>    

But if i run the code, i get always null. Why?

No comments:

Post a Comment