Hi
I have this in my settings.xml
<settings>
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<database.driver>oracle.jdbc.driver.OracleDriver</database.driver>
<database.url>jdbc:oracle:thin:@myhome:1521:orcl</database.url>
<database.username>foo</database.username>
<database.password>bar</database.password>
</properties>
</profile>
</profiles>
</settings>
And I have tried with these in my pom.xml:
<properties>
<db.driver>oracle.jdbc.OracleDriver</db.driver>
<db.url>${database.url}</db.url>
<db.username>${database.username}</db.username>
<db.password>${database.password}</db.password>
</properties>
And this:
<properties>
<database.driver>oracle.jdbc.OracleDriver</database.driver>
<database.url>dummy</database.url>
<database.username>dummy</database.username>
<database.password>dummy</database.password>
</properties>
I still get null with System.getProperty
Med venlig hilsen / Kind regards
Søren Krogh Neigaard
Systems Engineer
Søren Frichs Vej 39, 8000 Aarhus C
Denmark
Mobile +4541965252
[email protected]
www.systematic.com
-----Original Message-----
From: Martin Höller [mailto:[email protected]]
Sent: 5. februar 2010 08:30
To: Maven Users List
Subject: Re: Read properties from pom.xml from Java
Am Freitag, 5. Februar 2010 07:45:51 schrieb Søren Krogh Neigaard:
> Thank you all for your answers
>
> I tried adding the following to my pom.xml
>
> <properties>
> <database.driver>oracle.jdbc.OracleDriver</database.driver>
> <database.url>${database.url}</database.url>
> <database.username>${database.username}</database.username>
> <database.password>${database.password}</database.password>
> </properties>
>
> And tried reading with System.getProperty("database.username"), but it
> gave me null.
>
> The reason for the ${database.url} and so on, is that it gets its
> values from either a default settings.xml or a user specific
> settings.xml, and that is how I need it to be.
It's as Anders wrote already. If you want to use the same property names in
settings.xml and pom.xml you have to put them in a profile, that's how I do it
and it works. The profile could be <activeByDefault> if you prefer.
So your settings.xml could look like this:
<settings>
<profiles>
<profile>
<id>someProf</id>
<activation>
<activeByDefault/>
</activation>
<properties>
<database.url>someUrl</database.url>
</properties>
</profile>
</profiles>
</settings>
And your pom.xml would be this:
<project>
...
<properties>
<database.url>someDummyValue</database.url>
</properties>
</project>
Now reading the properties via System.getProperty("database.url") shoud work.
hth,
- martin
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]