简体   繁体   English

Maven中的环境变量

[英]Environment variables in maven

I am developing a plugin to deploy my application in pre-integration-phase in maven. 我正在开发一个插件,以在Maven的预集成阶段部署我的应用程序。 Now when the application boots up and all beans are created, then inside a setter method a env variable is passed whose value is fetched. 现在,当应用程序启动并创建了所有bean时,则在setter方法内部传递了一个env变量,其值被获取。

public void setEnvName(final String passwordEnvName) {
    super.setPassword(System.getenv(passwordEnvName));
}

Usage being 用法是

<bean id="environmentVariablesConfiguration" class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
    <property name="algorithm" value="PBEWithMD5AndDES" />
    <property name="passwordEnvName" value="PRIVATE_KEY" />
</bean>

Now i cannot set this variable in unix boxes. 现在,我无法在Unix框中设置此变量。 I tried the following 我尝试了以下

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <configuration>
                <tasks>
                    <exec executable="env">
                        <env key="PRIVATE_KEY" value="PASSWORD_KEY"/>
                    </exec>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

but it always comes as null. 但它始终为null。 Is there way any way I can achieve this? 有什么办法可以实现这一目标吗?

Maven is only executed at build time, not at runtime. Maven仅在构建时执行,而不在运行时执行。 So even if you set the env variable when you build, at runtime it will be empty if : 因此,即使在构建时设置了env变量,在运行时,如果满足以下条件,它将为空:

  • the program runs on another system than it was build 该程序在其生成的其他系统上运行
  • the env var was not set permanently, but only for the current process, so when it ends the env var is gone. env var不是永久设置的,而是仅针对当前进程设置的,因此结束时env var消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM