How to specify a global system property for java applications?

I am trying to integrate Cobertura in our test environment in order to be able to capture code coverage information. Tests are run from ant scripts using ANT junit tasks , and there are more than 50 ant script files (build.xml) with one or more junit task definitions.

According to the Cobertura doc , junit tests must be provided for the cobertura coverage data file through the sysproperty nested element of the sysproperty task. For me, this means that I will need to update all of these 50+ files to indicate the sysproperty element for junit tasks, which I plan to do as a last resort.

I run my tests on Linux (CentOS) , and I would like to know if there is a way to specify a global system property (-Dxxx=yyy) so that the system property is available to all java applications running on the system.

-EDIT-
Junit tests run in a forked JVM. <junit fork="yes" ...

+4
source share
2 answers

You can try setting the environment variable ANT_OPTS .


ANT_OPTS - command line arguments to be passed to the JVM. For example, you can define system properties or set the maximum Java heap size here.


-Edit -

You must set the _JAVA_OPTIONS environment _JAVA_OPTIONS . Here and here there is information about this.

+7
source

alternatively set the environment variable and in ant script use:

 <property environment="env"/> <echo>${env.yourEnvVariable}</echo> ... 

The advantage of using ANT_OPTS (which is primarily intended for internal ant settings, such as fe VM parameters ..) is the ability to customize using user environment variables, while ANT_ARGS is "static" for all ant scripts.

0
source

Source: https://habr.com/ru/post/1381565/


All Articles