Created
August 6, 2015 14:10
-
-
Save passionne/ff5a3db472267f720b54 to your computer and use it in GitHub Desktop.
update java library path programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Inspired by : http://blog.cedarsoft.com/2010/11/setting-java-library-path-programmatically/ | |
function testJavaVersion() { | |
version=$1 | |
echo "java ${version}" | |
docker run --rm -t -v "$(pwd):/opt" \ | |
java:${version} \ | |
/bin/bash -c "cd /opt && javac UpdateJavaLibPath.java && java UpdateJavaLibPath && rm UpdateJavaLibPath.class" | |
} | |
for version in 6 7 8 | |
do | |
testJavaVersion $version | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.ClassLoader; | |
import java.lang.String; | |
import java.lang.System; | |
import java.lang.reflect.Field; | |
class UpdateJavaLibPath { | |
public static String printLibPath() { | |
String current = System.getProperty("java.library.path"); | |
System.out.println(String.format("current = %s", current)); | |
return current; | |
} | |
public static void main(String[] args) { | |
String current = printLibPath(); | |
System.setProperty( "java.library.path", current + ":/tmp" ); | |
try { | |
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); | |
fieldSysPath.setAccessible( true ); | |
fieldSysPath.set( null, null ); | |
printLibPath(); | |
} catch (NoSuchFieldException e) { | |
e.printStackTrace(); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment