You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Martin Trummer <ma...@24act.com> on 2009/10/19 17:12:27 UTC

how to set environment variables

hi,

I've already read a lot about this
seems, that it's not possible to set env-vars in a pom.xml or
profiles.xml file in maven 2
is that correct?

does anyone know a workaround or a mini-plugin that allows to set those
env vars?

TIA, martin

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


RE: how to set environment variables

Posted by mars1412 <ma...@gmail.com>.
seems there's really no easy way to set env vars directly

in general I think that this is ok and you should not set env vars directly,
but I have a good exception to this rule: it is described in the paragraph
"Using Saxon (but not as default)" of 
http://martin-trummer.blogspot.com/2009/11/wysiwyg-gotchas.html Blog:
WYSIWYG gotchas 


the solution I came up with is to write my own little mojo that I can pass
the env-vars I want to set.
I bind the plugin execution to the early validate phase and pass the
properties like this:

&lt;configuration&gt;
	&lt;environmentVariables&gt;
	 	&lt;property&gt;
	 		&lt;name&gt;javax.xml.transform.TransformerFactory&lt;/name&gt;
	 	
&lt;value&gt;com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl&lt;/value&gt;
	 	&lt;/property&gt;
	 &lt;/environmentVariables&gt;
&lt;/configuration&gt;



in the mojo I simply call System.setProperty() for all given environment
vars - this works for my usecase.


However, beware that you should only use this if absolutely necessary
-- 
View this message in context: http://old.nabble.com/how-to-set-environment-variables-tp25960613p26525313.html
Sent from the Maven - Users mailing list archive at Nabble.com.

RE: how to set environment variables

Posted by Martin Gainty <mg...@hotmail.com>.
Good Afternoon Martin

i presume maven is called from a cmd/bash/cshell/kshell (shell environment) so one would need to reach back and change the configuration of the invoking parent environment
(which i dont how to accomplish from any child shell)

there are workarounds such as modifying the system registry to update and or insert new environment variables but one would need to reach back and refresh the configuration variables from the updated configuration..
interested in looking for a cleaner solution

any takers?
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Subject: how to set environment variables
> Date: Mon, 19 Oct 2009 17:12:27 +0200
> From: martin.trummer@24act.com
> To: users@maven.apache.org
> 
> hi,
> 
> I've already read a lot about this
> seems, that it's not possible to set env-vars in a pom.xml or
> profiles.xml file in maven 2
> is that correct?
> 
> does anyone know a workaround or a mini-plugin that allows to set those
> env vars?
> 
> TIA, martin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
 		 	   		  
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/171222986/direct/01/

RE: how to set environment variables

Posted by "Edelson, Justin" <Ju...@mtvstaff.com>.
Those are Maven properties, not environment variables. You can't set
environment variables for the current process in Java at all, let alone
in Maven. If you're forking a new process, you may be able to set
environment variables on the subprocess via ProcessBuilder.

Justin

-----Original Message-----
From: Manuel Grau [mailto:mangrar@gmail.com] 
Sent: Monday, October 19, 2009 11:49 AM
To: Maven Users List
Subject: Re: how to set environment variables

Is not possible? I'm using them. Take a look to my pom:

    <profiles>
        <profile>
            <id>development</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <property>
                    <name>env</name>
                    <value>dev</value>
                </property>
            </activation>
            <build>
                <filters>
                    <filter>
                        pom.dev.properties
                    </filter>
                </filters>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <groupId>org.apache.maven.plugins</groupId>
                        <version>2.1-beta-1</version>
                        <configuration>
                            <filtering>true</filtering>
                            <filters>
                                <filter>pom.dev.properties</filter>
                            </filters>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>test</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>test</value>
                </property>
            </activation>
            <build>
                <filters>
                    <filter>
                        pom.test.properties
                    </filter>
                </filters>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <groupId>org.apache.maven.plugins</groupId>
                        <version>2.1-beta-1</version>
                        <configuration>
                            <filtering>true</filtering>
                            <filters>
                                <filter>pom.test.properties</filter>
                            </filters>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>pre-produccion</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>pre</value>
                </property>
            </activation>
            <build>
                <filters>
                    <filter>
                        pom.pre.properties
                    </filter>
                </filters>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <groupId>org.apache.maven.plugins</groupId>
                        <version>2.1-beta-1</version>
                        <configuration>
                            <filtering>true</filtering>
                            <filters>
                                <filter>pom.pre.properties</filter>
                            </filters>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>produccion</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>prod</value>
                </property>
            </activation>
            <build>
                <filters>
                    <filter>
                        pom.prod.properties
                    </filter>
                </filters>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <groupId>org.apache.maven.plugins</groupId>
                        <version>2.1-beta-1</version>
                        <configuration>
                            <filtering>true</filtering>
                            <filters>
                                <filter>pom.prod.properties</filter>
                            </filters>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

As you can see we are using 4 environment settings. In each one, we load
a different properties file to filter recources.

2009/10/19 Martin Trummer <ma...@24act.com>

> hi,
>
> I've already read a lot about this
> seems, that it's not possible to set env-vars in a pom.xml or 
> profiles.xml file in maven 2 is that correct?
>
> does anyone know a workaround or a mini-plugin that allows to set 
> those env vars?
>
> TIA, martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


--
"Computer science is not about computers any more than astronomy is
about telescopes." E.W. Dijkstra (1930-2002)

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


Re: how to set environment variables

Posted by Manuel Grau <ma...@gmail.com>.
Is not possible? I'm using them. Take a look to my pom:

    <profiles>
        <profile>
            <id>development</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <property>
                    <name>env</name>
                    <value>dev</value>
                </property>
            </activation>
            <build>
                <filters>
                    <filter>
                        pom.dev.properties
                    </filter>
                </filters>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <groupId>org.apache.maven.plugins</groupId>
                        <version>2.1-beta-1</version>
                        <configuration>
                            <filtering>true</filtering>
                            <filters>
                                <filter>pom.dev.properties</filter>
                            </filters>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>test</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>test</value>
                </property>
            </activation>
            <build>
                <filters>
                    <filter>
                        pom.test.properties
                    </filter>
                </filters>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <groupId>org.apache.maven.plugins</groupId>
                        <version>2.1-beta-1</version>
                        <configuration>
                            <filtering>true</filtering>
                            <filters>
                                <filter>pom.test.properties</filter>
                            </filters>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>pre-produccion</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>pre</value>
                </property>
            </activation>
            <build>
                <filters>
                    <filter>
                        pom.pre.properties
                    </filter>
                </filters>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <groupId>org.apache.maven.plugins</groupId>
                        <version>2.1-beta-1</version>
                        <configuration>
                            <filtering>true</filtering>
                            <filters>
                                <filter>pom.pre.properties</filter>
                            </filters>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>produccion</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>prod</value>
                </property>
            </activation>
            <build>
                <filters>
                    <filter>
                        pom.prod.properties
                    </filter>
                </filters>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <groupId>org.apache.maven.plugins</groupId>
                        <version>2.1-beta-1</version>
                        <configuration>
                            <filtering>true</filtering>
                            <filters>
                                <filter>pom.prod.properties</filter>
                            </filters>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

As you can see we are using 4 environment settings. In each one, we load a
different properties file to filter recources.

2009/10/19 Martin Trummer <ma...@24act.com>

> hi,
>
> I've already read a lot about this
> seems, that it's not possible to set env-vars in a pom.xml or
> profiles.xml file in maven 2
> is that correct?
>
> does anyone know a workaround or a mini-plugin that allows to set those
> env vars?
>
> TIA, martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
"Computer science is not about computers any more than astronomy is about
telescopes." E.W. Dijkstra (1930-2002)