Re: Getting profile settings values in a Java class
You need to provide more information. Ron On 06/12/2012 2:09 PM, Javix wrote: it means true Regards From: Ron Wheeler [via Maven] [ml-node+s40175n5735905...@n5.nabble.com] Sent: 06 December 2012 14:33 To: CAMBOUR Serguei Subject: Re: Getting profile settings values in a Java class Or the error messages. Or what the "it" is in "So I have to set it up explicitly every time in the POM file. Here is my configuration:" Ron On 06/12/2012 3:35 AM, Anders Hammar wrote: This is probably difficult to solve without access to the actual problematic project. /Anders On Thu, Dec 6, 2012 at 9:25 AM, Javix <[hidden email]> wrote: I knew those option to desactivate a profile. The problem that I can't figure out how to solve is WHY the same Maven configuration works in one project and not at all in another? By the way, if comment out the line true and run mvn test -P [profile_to_use] it works fine too. But in another project, no matter the way I use to run Maven tests (commenting out the profile activation lines, running with negation option (![profile_not_to_use], [profile_to_use], it does not work and fails. So I have to set it up explicitly every time in the POM file. Here is my configuration: Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100) Maven home: C:\Apache\apache-maven-3.0.4 Java version: 1.6.0_21, vendor: Sun Microsystems Inc. Java home: C:\Program Files\Java\jdk1.6.0_21\jre Default locale: fr_FR, platform encoding: Cp1252 OS name: "windows xp", version: "5.1", arch: "x86", family: "windows" Regards -- View this message in context: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735884.html Sent from the Maven - Users mailing list archive at Nabble.com. - To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] -- Ron Wheeler President Artifact Software Inc email: [hidden email] skype: ronaldmwheeler phone: 866-970-2435, ext 102 - To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] If you reply to this email, your message will be added to the discussion below: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735905.html To unsubscribe from Getting profile settings values in a Java class, click here<http://maven.40175.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5722740&code=c2VyZ3VlaS5jYW1ib3VyQGF0b3MubmV0fDU3MjI3NDB8MTY2NTQxNzk3MQ==>. NAML<http://maven.40175.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité du groupe Atos ne pourra être engagée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être engagée pour tout dommage résultant d'un virus transmis. This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos group liability cannot be triggered for the message content. Although the sender endeavors to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted. -- View this message in context: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735950.html Sent from the Maven - Users mailing list archive at Nabble.com. -- 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
RE: Getting profile settings values in a Java class
it means true Regards From: Ron Wheeler [via Maven] [ml-node+s40175n5735905...@n5.nabble.com] Sent: 06 December 2012 14:33 To: CAMBOUR Serguei Subject: Re: Getting profile settings values in a Java class Or the error messages. Or what the "it" is in "So I have to set it up explicitly every time in the POM file. Here is my configuration:" Ron On 06/12/2012 3:35 AM, Anders Hammar wrote: > This is probably difficult to solve without access to the actual > problematic project. > > /Anders > > > On Thu, Dec 6, 2012 at 9:25 AM, Javix <[hidden email]> > wrote: > >> I knew those option to desactivate a profile. The problem that I can't >> figure >> out how to solve is WHY the same Maven configuration works in one project >> and not at all in another? By the way, if comment out the line >> >> >>true >> >> >> and run >> >> mvn test -P [profile_to_use] >> >> it works fine too. But in another project, no matter the way I use to run >> Maven tests (commenting out the profile activation lines, running with >> negation option (![profile_not_to_use], [profile_to_use], it does not work >> and fails. So I have to set it up explicitly every time in the POM file. >> Here is my configuration: >> >> Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100) >> Maven home: C:\Apache\apache-maven-3.0.4 >> Java version: 1.6.0_21, vendor: Sun Microsystems Inc. >> Java home: C:\Program Files\Java\jdk1.6.0_21\jre >> Default locale: fr_FR, platform encoding: Cp1252 >> OS name: "windows xp", version: "5.1", arch: "x86", family: "windows" >> >> Regards >> >> >> >> -- >> View this message in context: >> http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735884.html >> Sent from the Maven - Users mailing list archive at Nabble.com. >> >> - >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> -- Ron Wheeler President Artifact Software Inc email: [hidden email] skype: ronaldmwheeler phone: 866-970-2435, ext 102 ------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] If you reply to this email, your message will be added to the discussion below: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735905.html To unsubscribe from Getting profile settings values in a Java class, click here<http://maven.40175.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5722740&code=c2VyZ3VlaS5jYW1ib3VyQGF0b3MubmV0fDU3MjI3NDB8MTY2NTQxNzk3MQ==>. NAML<http://maven.40175.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité du groupe Atos ne pourra être engagée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être engagée pour tout dommage résultant d'un virus transmis. This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos group liability cannot be triggered for the message content. Although the sender endeavors to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted. -- View this message in context: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735950.html Sent from the Maven - Users mailing list archive at Nabble.com.
Re: Getting profile settings values in a Java class
Or the error messages. Or what the "it" is in "So I have to set it up explicitly every time in the POM file. Here is my configuration:" Ron On 06/12/2012 3:35 AM, Anders Hammar wrote: This is probably difficult to solve without access to the actual problematic project. /Anders On Thu, Dec 6, 2012 at 9:25 AM, Javix wrote: I knew those option to desactivate a profile. The problem that I can't figure out how to solve is WHY the same Maven configuration works in one project and not at all in another? By the way, if comment out the line true and run mvn test -P [profile_to_use] it works fine too. But in another project, no matter the way I use to run Maven tests (commenting out the profile activation lines, running with negation option (![profile_not_to_use], [profile_to_use], it does not work and fails. So I have to set it up explicitly every time in the POM file. Here is my configuration: Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100) Maven home: C:\Apache\apache-maven-3.0.4 Java version: 1.6.0_21, vendor: Sun Microsystems Inc. Java home: C:\Program Files\Java\jdk1.6.0_21\jre Default locale: fr_FR, platform encoding: Cp1252 OS name: "windows xp", version: "5.1", arch: "x86", family: "windows" Regards -- View this message in context: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735884.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
Re: Getting profile settings values in a Java class
This is probably difficult to solve without access to the actual problematic project. /Anders On Thu, Dec 6, 2012 at 9:25 AM, Javix wrote: > I knew those option to desactivate a profile. The problem that I can't > figure > out how to solve is WHY the same Maven configuration works in one project > and not at all in another? By the way, if comment out the line > > > true > > > and run > > mvn test -P [profile_to_use] > > it works fine too. But in another project, no matter the way I use to run > Maven tests (commenting out the profile activation lines, running with > negation option (![profile_not_to_use], [profile_to_use], it does not work > and fails. So I have to set it up explicitly every time in the POM file. > Here is my configuration: > > Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100) > Maven home: C:\Apache\apache-maven-3.0.4 > Java version: 1.6.0_21, vendor: Sun Microsystems Inc. > Java home: C:\Program Files\Java\jdk1.6.0_21\jre > Default locale: fr_FR, platform encoding: Cp1252 > OS name: "windows xp", version: "5.1", arch: "x86", family: "windows" > > Regards > > > > -- > View this message in context: > http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735884.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 > >
Re: Getting profile settings values in a Java class
I knew those option to desactivate a profile. The problem that I can't figure out how to solve is WHY the same Maven configuration works in one project and not at all in another? By the way, if comment out the line true and run mvn test -P [profile_to_use] it works fine too. But in another project, no matter the way I use to run Maven tests (commenting out the profile activation lines, running with negation option (![profile_not_to_use], [profile_to_use], it does not work and fails. So I have to set it up explicitly every time in the POM file. Here is my configuration: Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100) Maven home: C:\Apache\apache-maven-3.0.4 Java version: 1.6.0_21, vendor: Sun Microsystems Inc. Java home: C:\Program Files\Java\jdk1.6.0_21\jre Default locale: fr_FR, platform encoding: Cp1252 OS name: "windows xp", version: "5.1", arch: "x86", family: "windows" Regards -- View this message in context: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735884.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
Re: Getting profile settings values in a Java class
> so you need to do ' -P vm,!dev ' > That is not true. Enabling the "vm" profile will disable the activeByDefault one ("dev") automatically. /Anders > > > > > > On 12/5/12 7:53 AM, "Javix" wrote: > > >I'm back with a strange behaviour. In a separate project which has > >profiles > >defined exactly the same way, passing the option '-P [profile name]' does > >not work at all, Maven continues to use the default activated profile. > >Here > >is a working example: > > > >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";> > > 4.0.0 > > > > com.spot.sncf > > java_cukes > > 1.0-SNAPSHOT > > jar > > > > java_cukes > > http://maven.apache.org > > > > > > > > org.apache.maven.plugins > > > maven-compiler-plugin > > 2.3.2 > > > > 1.6 > > 1.6 > > > > > > > > > > org.apache.maven.plugins > > maven-site-plugin > > 3.1 > > > > > > > > > org.apache.maven.plugins > > > maven-surefire-report-plugin > > > 2.4.3 > > > > > > > > > > > > > > > > > > src/main/resources > > true > > > > > > > > > > > > > UTF-8 > > > UTF-8 >g> > > > > > > > > > > dev > > > > true > > > > > > http://toto.com > > > > > > > > vm > > > > http://yoyo.com > > > > > > > > > > > > > > > > info.cukes > > cucumber-picocontainer > > 1.1.1 > > test > > > > > > info.cukes > > cucumber-junit > > 1.1.1 > > test > > > > > > junit > > junit > > 4.10 > > test > > > > > > > > > > > >Executing > > > >mvn test > > > >will run the activated default profile (vm). > > > >Running > > > >mvn test -P vm > > > >will run the 'vm' prifile. > > > >Using the same but in a different project runs only the activated profile, > >no matter if I pass -P option. > >Any idea? > > > >Thanks > > > > > > > > > > > >-- > >View this message in context: > > > http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java > >-class-tp5722740p5735821.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 > > > > > - > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > For additional commands, e-mail: users-h...@maven.apache.org > >
Re: Getting profile settings values in a Java class
Taken from http://maven.apache.org/guides/introduction/introduction-to-profiles.html Deactivating a profile Starting with Maven 2.0.10, one or more profiles can be deactivated using the command line by prefixing their identifier with either the character '!' or '-' as shown below: mvn groupId:artifactId:goal -P !profile-1,!profile-2 This can be used to deactivate profiles marked as activeByDefault or profiles that would otherwise be activated through their activation config. so you need to do ' -P vm,!dev ' On 12/5/12 7:53 AM, "Javix" wrote: >I'm back with a strange behaviour. In a separate project which has >profiles >defined exactly the same way, passing the option '-P [profile name]' does >not work at all, Maven continues to use the default activated profile. >Here >is a working example: > >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";> > 4.0.0 > > com.spot.sncf > java_cukes > 1.0-SNAPSHOT > jar > > java_cukes > http://maven.apache.org > > > > org.apache.maven.plugins > maven-compiler-plugin > 2.3.2 > > 1.6 > 1.6 > > > > > org.apache.maven.plugins > maven-site-plugin > 3.1 > > > > > org.apache.maven.plugins > > maven-surefire-report-plugin > 2.4.3 > > > > > > > > > src/main/resources > true > > > > > > > UTF-8 > > UTF-8g> > > > > > dev > > true > > > http://toto.com > > > > vm > > http://yoyo.com > > > > > > > > info.cukes > cucumber-picocontainer > 1.1.1 > test > > > info.cukes > cucumber-junit > 1.1.1 > test > > > junit > junit > 4.10 > test > > > > > >Executing > >mvn test > >will run the activated default profile (vm). > >Running > >mvn test -P vm > >will run the 'vm' prifile. > >Using the same but in a different project runs only the activated profile, >no matter if I pass -P option. >Any idea? > >Thanks > > > > > >-- >View this message in context: >http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java >-class-tp5722740p5735821.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 > - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Getting profile settings values in a Java class
I'm back with a strange behaviour. In a separate project which has profiles defined exactly the same way, passing the option '-P [profile name]' does not work at all, Maven continues to use the default activated profile. Here is a working example: 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";> 4.0.0 com.spot.sncf java_cukes 1.0-SNAPSHOT jar java_cukes http://maven.apache.org org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.6 1.6 org.apache.maven.plugins maven-site-plugin 3.1 org.apache.maven.plugins maven-surefire-report-plugin 2.4.3 src/main/resources true UTF-8 UTF-8 dev true http://toto.com vm http://yoyo.com info.cukes cucumber-picocontainer 1.1.1 test info.cukes cucumber-junit 1.1.1 test junit junit 4.10 test Executing mvn test will run the activated default profile (vm). Running mvn test -P vm will run the 'vm' prifile. Using the same but in a different project runs only the activated profile, no matter if I pass -P option. Any idea? Thanks -- View this message in context: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5735821.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
Re: Getting profile settings values in a Java class
Hi Javix, yes, this is what I mean. You may want to consider what emerged in this thread about the goodness of this practice. Cheers, M. On 21/09/2012 10:55, Javix wrote: 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: - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Getting profile settings values in a Java class
Hi Roy, that's a useful addition. Indeed I do something similar with with some command-line tools. I ship them as a zip which contains: a .jar a .sh/.bat invoking commands and a default .properties file. For the latter, I want different defaults depending on the environment where I deploy final zip. I could just ask the users to point to the right .properties file, but the fact is that we have the dev/test/production environments and in the first two we want a situation that is as close as possible to the third. Thanks anyway. Marco. On 21/09/2012 01:32, Lyons, Roy wrote: I would like to say that there is definitely a better way. You *could* continue to use maven for filtering your properties, but I wouldn't use it as part of the build of the application. If you are simply using scp or other similarly crude method of deployment (meaning you are just deploying as a file transfer), I would say that you could set up a maven project on the server side which handle the deployment. You can setup a pom.xml with all of the maven objects as dependencies (including your jar/war/ear files you already built) and then use the assembly plugin to create a staged application environment including a variable replacement on template-ized external property files which your application can reference (the replacement being done by filtering within assembly directives). As a matter of fact, I would argue that this could be all stuffed in a git repository and your installation could be done with: ssh $servername "git clone -b $branchname $gitprojecturl \; cd $targetdir \; mvn -P $envname dependency:resolve assembly:assembly \; $startscript" Or ssh $servername "cd $targetdir \; $stopscript \; git clean -f \; git pull origin \; mvn -P $envname dependency:resolve assembly:assembly \; $startscript" Long and short is that it is still possible to do what you want with maven, but not inside of the box you are thinking in. As a configuration engineer, I know that environment specific properties (and usually other properties too) should always be stored in files external to your jar. "The Maven Way" will tell you to make re-usable stuff. Your deployment artifacts are no exception. Don't force a rebuild when a property has to change. Your QA folks will be extra thankful since the jar/war/ear will maintain a constant md5sum that they can use to justify not performing full regression tests. Disclaimer: We are using a highly sophisticated and expensive tool for deployments and can't use this method due to auditing needs. However we still have our tool perform a post-process interpolation of variables within config files based on environment to achieve a similar end result. Also, to prevent a flame-war -- I am presenting this as a feasible alternative way to use maven for the purpose of filtering properties based on a profile being set (the original poster's intention) that will perhaps help the original poster think outside of the box to achieve their goals. Thanks, Roy - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Getting profile settings values in a Java class
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: 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";> 4.0.0 com.spot.sncf java_cukes 1.0-SNAPSHOT jar java_cukes http://maven.apache.org org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.6 1.6 org.apache.maven.plugins maven-site-plugin 3.1 org.apache.maven.plugins maven-surefire-report-plugin 2.4.3 src/main/resources true UTF-8 toto true http://toto.com yoyo http://yoyo.com info.cukes cucumber-java 1.0.14 test info.cukes cucumber-junit 1.0.14 test junit junit 4.10 test 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
Re: Getting profile settings values in a Java class
Thanks a lot for your reply. I tried to use your way, but: 1. I already have a test folder under 'src' (scr/main and src/test which is a standard Maven project structure). 2. I didn't really understand (sorry for that, - I'm not a Maven Guru :( ) the syntax to use in case of test prefix. I'd like to set up 4 different environment with their corresponding properties. 3. I put a properties file 'app.properties' in scr/test/resources with the following content: host={test.host} 4. Tried to get properties in a java class as follows: public Person() { initProperies(); System.out.println("Got system properties: " + properties.getProperty("host")); } private void initProperies(){ properties = new Properties(); try { properties.load(new FileInputStream("app.properties")); } catch (IOException ex) { Logger.getLogger(Person.class.getName()).log(Level.SEVERE, null, ex); } } 5. Got the FileNotFoundException when running 'mvn clean test' command. Any idea how to: - separate all the 4 profiles - get the needed values in a Java class Thanks in advance. -- View this message in context: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740p5722845.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
Re: Getting profile settings values in a Java class
I would like to say that there is definitely a better way. You *could* continue to use maven for filtering your properties, but I wouldn't use it as part of the build of the application. If you are simply using scp or other similarly crude method of deployment (meaning you are just deploying as a file transfer), I would say that you could set up a maven project on the server side which handle the deployment. You can setup a pom.xml with all of the maven objects as dependencies (including your jar/war/ear files you already built) and then use the assembly plugin to create a staged application environment including a variable replacement on template-ized external property files which your application can reference (the replacement being done by filtering within assembly directives). As a matter of fact, I would argue that this could be all stuffed in a git repository and your installation could be done with: ssh $servername "git clone -b $branchname $gitprojecturl \; cd $targetdir \; mvn -P $envname dependency:resolve assembly:assembly \; $startscript" Or ssh $servername "cd $targetdir \; $stopscript \; git clean -f \; git pull origin \; mvn -P $envname dependency:resolve assembly:assembly \; $startscript" Long and short is that it is still possible to do what you want with maven, but not inside of the box you are thinking in. As a configuration engineer, I know that environment specific properties (and usually other properties too) should always be stored in files external to your jar. "The Maven Way" will tell you to make re-usable stuff. Your deployment artifacts are no exception. Don't force a rebuild when a property has to change. Your QA folks will be extra thankful since the jar/war/ear will maintain a constant md5sum that they can use to justify not performing full regression tests. Disclaimer: We are using a highly sophisticated and expensive tool for deployments and can't use this method due to auditing needs. However we still have our tool perform a post-process interpolation of variables within config files based on environment to achieve a similar end result. Also, to prevent a flame-war -- I am presenting this as a feasible alternative way to use maven for the purpose of filtering properties based on a profile being set (the original poster's intention) that will perhaps help the original poster think outside of the box to achieve their goals. Thanks, Roy On 9/20/12 4:48 PM, "Zak Mc Kracken" wrote: >OK, I understand that in general it should be considered an >anti-pattern. Despite that, in my organisation we deploy a number of >internal tools on a couple of servers and with different configurations >(dev, test, production). To achieve this we do what it was originally >asked in this thread. > >I think the only way for that with the assistance of Maven is how it was >suggested: use property files with ${placeholders} and tell Maven to >resolve them, then define the corresponding properties in the profiles. >This is an example: > > http://github.com/EBIBioSamples/core_model/blob/master/pom.xml > >Note that the and sections have: >true and then there are parametrised files like: > >http://github.com/EBIBioSamples/core_model/blob/master/src/test/resources/ >hibernate.properties > >In this particular module, things are set only to change the >configuration that JUnit tests receive, but the trick works the same way >if you have another property file in src/main/resources. Yes, it makes >the final jar dependent on Maven profiles and on a particular >environment, however it may be acceptable in certain situations (like >ours). > >Marco. > > >On 20/09/2012 21:16, Ron Wheeler wrote: >> 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 >> >> > > > >- >To unsubscribe, e-mail: users-unsubscr...@maven.apache.org >For additional commands, e-mail: users-h...@maven.apache.org > - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Getting profile settings values in a Java class
OK, I understand that in general it should be considered an anti-pattern. Despite that, in my organisation we deploy a number of internal tools on a couple of servers and with different configurations (dev, test, production). To achieve this we do what it was originally asked in this thread. I think the only way for that with the assistance of Maven is how it was suggested: use property files with ${placeholders} and tell Maven to resolve them, then define the corresponding properties in the profiles. This is an example: http://github.com/EBIBioSamples/core_model/blob/master/pom.xml Note that the and sections have: true and then there are parametrised files like: http://github.com/EBIBioSamples/core_model/blob/master/src/test/resources/hibernate.properties In this particular module, things are set only to change the configuration that JUnit tests receive, but the trick works the same way if you have another property file in src/main/resources. Yes, it makes the final jar dependent on Maven profiles and on a particular environment, however it may be acceptable in certain situations (like ours). Marco. On 20/09/2012 21:16, Ron Wheeler wrote: 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 - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Getting profile settings values in a Java class
> System.out.println("## in the Person constructor"); > System.out.println("Got system properties: " + > System.getProperty("host")); Maven wasn't really built for this purpose/use case so I doubt you will be overly happy with how it is handled in Maven. Instead I think you should use traditional property files or even pull in a JNDI solution like Spring or Guice. Wayne - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Getting profile settings values in a Java class
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 Here is the POM file: 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";> 4.0.0 com.spot.sncf java_cukes 1.0-SNAPSHOT jar java_cukes http://maven.apache.org org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.6 1.6 org.apache.maven.plugins maven-site-plugin 3.1 org.apache.maven.plugins maven-surefire-report-plugin 2.4.3 ${host} UTF-8 dev http://toto.yoyo.com info.cukes cucumber-java 1.0.14 test info.cukes cucumber-junit 1.0.14 test junit junit 4.10 test 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
Re: Getting profile settings values in a Java class
Here is the POM file: 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";> 4.0.0 com.spot.sncf java_cukes 1.0-SNAPSHOT jar java_cukes http://maven.apache.org org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.6 1.6 org.apache.maven.plugins maven-site-plugin 3.1 org.apache.maven.plugins maven-surefire-report-plugin 2.4.3 ${host} UTF-8 dev http://toto.yoyo.com info.cukes cucumber-java 1.0.14 test info.cukes cucumber-junit 1.0.14 test junit junit 4.10 test 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
Re: Getting profile settings values in a Java class
> I defined several profiles in the POM file. Each profile should have its own > properties defined for host name, DB config values , etc. - to use them > later in the Java code. How is it possible (I hope it is) to define that in > the POM file? What are you trying to achieve? What have you already tried which failed? Wayne - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Getting profile settings values in a Java class
I defined several profiles in the POM file. Each profile should have its own properties defined for host name, DB config values , etc. - to use them later in the Java code. How is it possible (I hope it is) to define that in the POM file? Thanks -- View this message in context: http://maven.40175.n5.nabble.com/Getting-profile-settings-values-in-a-Java-class-tp5722740.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