Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ezhov-da/17035f57d82f87ac1d7080057764f25f to your computer and use it in GitHub Desktop.
Save ezhov-da/17035f57d82f87ac1d7080057764f25f to your computer and use it in GitHub Desktop.
java динамическая загрузка dll
[code:]java[:code]
import java.io.File;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
import ru.ezhov.schedulerproductiontasks.tools.XmlConfig;
/**
* Класс, который устанавливает "java.library.path"
* <p>
* @author ezhov_da
*/
public class ActiveLibraryPath
{
private static final Logger LOG = Logger.getLogger(ActiveLibraryPath.class.getName());
public static final synchronized void setLibraryPath(String path)
{
try
{
System.setProperty("java.library.path", path);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (Exception ex)
{
LOG.log(Level.SEVERE, "error load library path", ex);
}
}
public static final synchronized void setPath()
{
LOG.info("устанавливаем пути dll");
String libx64 = XmlConfig.getPrivatePropertyConnection("x64");
LOG.log(Level.INFO, "64: {0}", libx64);
String libx86 = XmlConfig.getPrivatePropertyConnection("x86");
LOG.log(Level.INFO, "86: {0}", libx86);
File filex64 = new File(libx64);
File filex86 = new File(libx86);
String ocArch = System.getProperty("sun.arch.data.model");
String fullPath = null;
if ("64".equals(ocArch))
{
fullPath = filex64.getAbsolutePath();
LOG.log(Level.INFO, "64: {0}", fullPath);
} else if ("32".equals(ocArch))
{
fullPath = filex86.getAbsolutePath();
LOG.log(Level.INFO, "32: {0}", fullPath);
}
setLibraryPath(fullPath);
}
}
[/code]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment