Last active
March 10, 2019 12:21
-
-
Save ezhov-da/fd6c03e7adc65d5bc98f8a628f2399bd to your computer and use it in GitHub Desktop.
java динамическое подключение dll с абсолютным путем
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
[code:]java[:code]import java.io.File; | |
import java.lang.reflect.Field; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javax.swing.JOptionPane; | |
import ru.ezhov.pathtofile.AbsolutePath; | |
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() | |
{ | |
try | |
{ | |
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); | |
String path = AbsolutePath.getAbsolutePath(ActiveLibraryPath.class) + File.separator; | |
File filex64 = new File(path + libx64); | |
File filex86 = new File(path + 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); | |
} catch (Exception ex) | |
{ | |
Logger.getLogger(ActiveLibraryPath.class.getName()).log(Level.SEVERE, null, ex); | |
//не нужно | |
} | |
} | |
} | |
[/code] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment