Environment Variable with Maven

前端 未结 9 2130
攒了一身酷
攒了一身酷 2020-11-28 03:24

I\'ve ported a project from Eclipse to Maven and I need to set an environment variable to make my project work.

In Eclipse, I go to \"Run -> Run configurations\" and

9条回答
  •  迷失自我
    2020-11-28 03:56

    You can just pass it on the command line, as

    mvn -DmyVariable=someValue install
    

    [Update] Note that the order of parameters is significant - you need to specify any options before the command(s).[/Update]

    Within the POM file, you may refer to system variables (specified on the command line, or in the pom) as ${myVariable}, and environment variables as ${env.myVariable}. (Thanks to commenters for the correction.)

    Update2

    OK, so you want to pass your system variable to your tests. If - as I assume - you use the Surefire plugin for testing, the best is to specify the needed system variable(s) within the pom, in your plugins section, e.g.

    
        
            ...
            
                org.apache.maven.plugins
                maven-surefire-plugin
                ...
                
                    ...
                    
                        conf
                    
                
            
            ...
        
    
    

提交回复
热议问题