The idea is to make the static field "sys_paths" null so that it would construct the paths from the changed value.
See the post here (Post#223 by AjaySingh516) http://forums.sun.com/thread.jspa?messageID=3744346#3744346
Class clazz = ClassLoader.class;
Field field = clazz.getDeclaredField("sys_paths");
boolean accessible = field.isAccessible();
if (!accessible)
field.setAccessible(true);
Object original = field.get(clazz);
// Reset it to null so that whenever "System.loadLibrary" is called, it
// will be reconstructed with the changed value.
field.set(clazz, null);
try {
// Change the value and load the library.
System.setProperty("java.library.path", "./libs/");
System.loadLibrary("mylibapr");
} finally {
// Revert back the changes.
field.set(clazz, original);
field.setAccessible(accessible);
}
.
gcj System Properties (See: Standard properties supported by libgcj)
http://gcc.gnu.org/onlinedocs/gcj/System-properties.html
.
Solution#2
: Set System environment variable at compile time
http://linux.die.net/man/1/gcj
For this you have to use parameter -Djava.library.path=./libs/
with gcj
From gcj manual (above link):
--main= CLASSNAME
This option is used when linking to specify the name of the class whose "main" method should be invoked when the resulting executable is run.
-Dname[=value]
This option can only be used with "--main". It defines a system property named name with value value. If value is not specified then it defaults to the empty string. These system properties are initialized at the program's startup and can be retrieved at runtime using the "java.lang.System.getProperty" method.
I have never worked with gcj but as per docs these system properties can be retrieved at runtime, hence it will be portable to other systems as well.
Also see: http://gcc.gnu.org/wiki/Statically_linking_libgcj?action=show&redirect=Statically+linking+libgcj