Search code examples
javaxmlantbuildjvm-arguments

Difference between System.setProperty in Java code and <sysproperty/> or <jvmargs> in ant xml


If I set the property in Java program code, it works:

try {
        System.setProperty("javax.net.ssl.trustStore", "/home/ylinghao/AllocationAnomaliesDetection/env/AllocationAnomaliesDetection-1.0/runtime/certs/InternalTrustStore.jks");
        System.setProperty("javax.net.ssl.trustStorePassword", "password");
    } catch (Exception e) {
        System.out.println("Failed to specify keystore for issue" + e);
    }

But If I try setting the property in <jvmarg> or <systproperty> in build.xml of ant, it fails. Could anyone tell me what is the difference? Thanks!


Solution

  • Your issue is that on your ant you are doing the build of your application. So the jvm settigns you are configuring there are for the execution of ant itself (or any auxiliar java process you yse, for example, to compile the code).

    So in your ant you are not affecting execution of your program, which is done in another java process when you start it.