Environment Variable with Maven

前端 未结 9 2064
攒了一身酷
攒了一身酷 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 04:02

    Following documentation from @Kevin's answer the below one worked for me for setting environment variable with maven sure-fire plugin

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <environmentVariables>
            <WSNSHELL_HOME>conf</WSNSHELL_HOME>
        </environmentVariables>
    </configuration>
    
    0 讨论(0)
  • 2020-11-28 04:04

    You could wrap your maven command in a bash script:

    #!/bin/bash
    
    export YOUR_VAR=thevalue
    mvn test
    unset YOUR_VAR
    
    0 讨论(0)
  • 2020-11-28 04:07

    in your code add:

    System.getProperty("WSNSHELL_HOME")

    Modify or add value property from maven command:

    mvn clean test -DargLine=-DWSNSHELL_HOME=yourvalue
    

    If you want to run it in Eclipse, add VM arguments in your Debug/Run configurations

    • Go to Run -> Run configurations
    • Select Tab Arguments
    • Add in section VM Arguments

    -DWSNSHELL_HOME=yourvalue

    See image example

    you don't need to modify the POM

    0 讨论(0)
提交回复
热议问题