Finally, I achived (I hope so, tell me if I'm wrong by pointing at some
pitfalls). Here is the updated version of the POM 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/xsd/maven-4.0.0.xsd";>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.spot.sncf</groupId>
    <artifactId>java_cukes</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>java_cukes</name>
    <url>http://maven.apache.org</url>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>                                        
                 
                </configuration>
            </plugin>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <reportPlugins>                        
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                           
<artifactId>maven-surefire-report-plugin</artifactId>
                            <version>2.4.3</version>
                        </plugin>            
                    </reportPlugins>                    
                </configuration>
            </plugin>                        
        </plugins>                
        
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>                                
            </resource>
        </resources>
        
    </build>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <profiles>
        <profile>
            <id>toto</id>   
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <host>http://toto.com</host>
            </properties>                                  
        </profile>        
        <profile>
            <id>yoyo</id>               
            <properties>
                <host>http://yoyo.com</host>
            </properties>                                  
        </profile>        
    </profiles>
        

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.0.14</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.0.14</version>
            <scope>test</scope>
        </dependency>
                
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
        
</project>

Call the host propoerty in Java:

public Person() {        
        initProperies();
        System.out.println("Got system properties: " +
properties.getProperty("host"));
    }
    
    private void initProperies(){
        properties = new Properties();
        try {
           
properties.load(getClass().getResourceAsStream("/app.properties"));
        } catch (IOException ex) {
            Logger.getLogger(Person.class.getName()).log(Level.SEVERE, null,
ex);
        }
    }

I put the app.properties file in src/mai/resources with the following
content:

host=${host}

And it worked for me. Thank you all.
Regards




--
View this message in context: 
http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5722849.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to