Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7616457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:53:33+00:00 2026-05-31T02:53:33+00:00

I need to execute some tests with maven, and pass a parameter from the

  • 0

I need to execute some tests with maven, and pass a parameter from the command line.

My java code should get the parameter as:
System.getenv(“my_parameter1”);

and I define the parameter in the pom.xml file as the example below:
(and latter, I’d modify the pom.xml to get the parameter from the common line mvn clean install -Dmy_parameter1=value1)

but it does not work; System.getenv(“my_parameter1”) returns null.
how should I define the parameter in the pom.xml file?

pom.xml

<project>
  ...
  <profiles>
    <profile>
      <properties>
        <my_parameter1>value1</my_parameter1>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <executions>
              <execution>
                <id>slowTest</id>
                <phase>test</phase>
                <goals>
                  <goal>test</goal>
                </goals>
                <configuration>
                  <skip>false</skip>
                  <includes>
                    <include>**/*Test.java</include>
                    <include>**/*TestSlow.java</include>
                  </includes>
                  <properties>
                    <my_parameter1>value1</my_parameter1>
                  </properties>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:53:35+00:00Added an answer on May 31, 2026 at 2:53 am

    System.getenv() reads environment variables, such as PATH. What you want is to read a system property instead. The -D[system property name]=[value] is for system properties, not environment variables.

    You have two options:

    1. If you want to use environment variables, use the OS-specific method of setting the environment variable my_parameter1 before you launch Maven. In Windows, use set my_parameter1=<value>, in ‘nix use export my_parameter1=<value>.

    2. You can use System.getProperty() to read the system property value from within your code.

    example:

    String param = System.getProperty("my_parameter1");
    

    In you surefire plugin configuration, you can use:

    <configuration>
        <systemPropertyVariables>
            <my_property1>${my_property1}</my_property1>
        </systemPropertyVariables>
    </configuration>
    

    Which takes the Maven property _my_property1_ and sets it also in your tests.

    More details about this here.

    I’m not sure if system properties from Maven are automatically passed to tests and/or whether fork mode affects whether this happens, so it’s probably a good idea to pass them in explicitly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to execute MDX query from command line (MS AS 2005). I have
i need to execute some javascript functions from delphi code, but this functions fails
I need execute some code before Windows shutdown process each time. So, I want
In an impersonation scenario related to Sharepoint I need to execute some code in
In my MSTest UnitTest project, before running any tests, I need to execute some
In a maven project I have some junit tests where I need to refer
I need to execute some dynamically generated code in Python and ensure that this
I need to execute some common code for several 'around' advices. So, I have
I am working on a bash script where I need to conditionally execute some
I need to execute a select and then update some of the rows in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.