Maven is not the place to set run-time information.
Trying to use profiles in this way, will only lead you to heartache and a dislike of Maven.

http://blog.artifact-software.com/tech/?p=150
http://blog.artifact-software.com/tech/?p=58

Ron


On 20/09/2012 11:21 AM, tobias maslowski wrote:
I'm not sure about what you want to do. I'll try to summarize anyways.

You have a java-application and want to configure this with settings
provided by maven-profiles.
So you did want to pass these settings to the system properties with maven
and read them later at runtime from within your application.

If I'm horribly wrong with that, please excuse me and nevermind.
If not:
I have seen stuff like configuration from profiles by filtering
configuration files for the properties.
This would work like: You have a config-File in the resources-directory,
and use filtering at resources-copy to inject your profile-specific
settings at build-time. In the application you just read this file and got
your settings.

That beeing said, I there are a few things you should be aware of:
maven is a tool to execute plugins(from my point of view) in a context of
several setting files and a directory tree.
In most cases you will just build your application with it - maven job well
done - and then run the application on your own(outside of the context of
maven).
So the idea of passing system-properties to the runtime of your application
is ... how to put this delicatly :)

What you actually did in the pom you showed us was to configure the
"reporting" plugin to provide this property at execution(e.g. in test-runs).
But this is not the runtime of your application but the test-phase of your
build-process.

Also there are a few people who had very bad experience with profiles, so
you might want to consider solving this by modularization. But I can't say
if that even suits your use-case.

Best regards.

2012/9/20 Javix <serguei.camb...@atos.net>

Here is 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>
                     <systemPropertyVariables>
                         <host>${host}</host>
                     </systemPropertyVariables>
                 </configuration>
             </plugin>


         </plugins>
     </build>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>

     <profiles>
         <profile>
             <id>dev</id>
             <properties>
                 <host>http://toto.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>


Here is what I tried to do in a Java class to get the property value:

public class Person {

     private int age;
     private String firstname;
     private String lastname;

     public Person() {
         System.out.println("############## in the Person constructor");
         System.out.println("Got system properties: " +
System.getProperty("host"));
     }
...
}

I got always NULL as property value.
Regards



--
View this message in context:
http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5722744.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




--
Ron Wheeler
President
Artifact Software Inc
email: rwhee...@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102


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

Reply via email to