Is -Djava.library.path=... equivalent to System.setProperty("java.library.path", ...)
java
Solution
Generally speaking, both approaches have the same net effect in that the system property `java.library.path` is set to the value `./lib`.
However, some system properties are only evaluated at specific points in time, such as the startup of the JVM. If `java.library.path` is among those properties (and your experiment seems to indicate that), then using the second approach will have no noticeable effect except for returning the new value on future invocations of `getProperty()`.
As a rule of thumb, using the `-D` command line property works on all system properties, while `System.setProperty()` only works on properties that are not only checked during startup.
Problem
I load an external library that is placed in `./lib`. Are these two solutions to set the java.library.path equivalent? Set path in console when executing jar: ``` java -Djava.library.path=./lib -jar myApplication.jar ``` Set path in the code before loading library: ``` System.setProperty("java.library.path", "./lib"); ``` If they are equivalent, why in the second solution can Java not find the library while the first one is ok? If not, is there a way the set the path in the code?