and then use them within your java ant task: This propertyset can be used on demand; when passed down to a new process, all current ant properties that match the given prefixes are passed down:
<java>
<!--copy all proxy settings from the running JVM-->
<syspropertyset refid="proxy.settings"/>
...
</java>
I completely missed the fact you were trying to pass java.library.path property!
As mentioned in this thread:
if you try to set its value outside of the java task, Ant ignores it. So I put all properties except for that one in my syspropertyset and it works as expected.
public class MyFeatureTest {
@Before
public void load_library_xxxxx() {
System.loadLibrary("library_name_without_extension");
}
@Test
public void on_that_case_my_feature_does_this() {
// ...
}
}
Search a line like [junit] '-Djava.library.path= within your ant output to check the presence and value of java.library.path. The expression [...] represent text that has been removed for clarity.
> ant test -v
[...]
test:
[mkdir] Skipping /home/user/my/dir/report because it already exists.
[junit] Implicitly adding /usr/share/ant/lib/junit.jar:[...] to CLASSPATH
[junit] Executing '/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java' with arguments:
[junit] '-Djava.library.path=/home/user/my/project/path/where/your/library/is/located'
[junit] '-classpath'
[junit] '/home/user/my/project/external/antlr.jar:[...]'
[junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
[junit] 'com.example.myproject.myfeature.MyFeatureTest'
[junit] 'skipNonTests=false'
[junit] 'filtertrace=true'
[junit] 'haltOnError=false'
[junit] 'haltOnFailure=false'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
[junit] 'showoutput=false'
[junit] 'outputtoformatters=true'
[junit] 'logfailedtests=true'
[junit] 'threadid=0'
[junit] 'logtestlistenerevents=false'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,/home/user/my/dir/report/TEST-com.example.myproject.myfeature.MyFeatureTest.xml'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,/home/user/my/dir/report/TEST-com.example.myproject.myfeature.MyFeatureTest.txt'
[junit] 'crashfile=/home/user/my/project/junitvmwatcher4952613017772370651.properties'
[junit] 'propsfile=/home/user/my/project/junit3999929381398716397.properties'
[junit]
[junit] The ' characters around the executable and arguments are
[junit] not part of the command.
[...]
<propertyset>
and<syspropertyset>
should be what you are looking forSee also this thread for instance.
You can set them one by one within your java ant task:
tedious... or you can pass them down as a block of Ant properties:
You can reference external system properties:
and then use them within your java ant task: This
propertyset
can be used on demand; when passed down to a new process, all current ant properties that match the given prefixes are passed down:I completely missed the fact you were trying to pass
java.library.path
property!As mentioned in this thread:
meaning:
will not work, but the following should:
(although you might try that with the "
fork
" attribute set to true if it does not work)(Note: you cannot modify its value though)
For JUnit ant task set your
java.library.path
in section<junit>
See
ant
manual, page JUnit, section<sysproperty>
for more details.The rest of this answer are details for beginners.
1. Load your library in your junit fixture
2. Set the
java.library.path
in your ant script3. Use
ant
option-v
to checkjava.library.path
Search a line like
[junit] '-Djava.library.path=
within yourant
output to check the presence and value ofjava.library.path
. The expression[...]
represent text that has been removed for clarity.I've managed to get it to work using the environment variable
ANT_OPTS
. I would like to see this done from a task if it's possible.