當前位置: 首頁>>代碼示例>>Java>>正文


Java Native.loadLibrary方法代碼示例

本文整理匯總了Java中com.sun.jna.Native.loadLibrary方法的典型用法代碼示例。如果您正苦於以下問題:Java Native.loadLibrary方法的具體用法?Java Native.loadLibrary怎麽用?Java Native.loadLibrary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.jna.Native的用法示例。


在下文中一共展示了Native.loadLibrary方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: CLibrary

import com.sun.jna.Native; //導入方法依賴的package包/類
public CLibrary() {
switch (Platform.get()) {
    case LinuxIntel32:
    case LinuxIntel64:
	delegate = (GenericCLibrary) Native.loadLibrary("c", DefaultCLibrary.class);
	constants = new LinuxConstants();
	break;
    case MacosIntel32:
	delegate = (GenericCLibrary) Native.loadLibrary("c", DefaultCLibrary.class);
	constants = new MacConstants();
	break;
    case SolarisIntel32:
    case SolarisIntel64:
    case SolarisSparc32:
    case SolarisSparc64:
	delegate = (GenericCLibrary) Native.loadLibrary("c", DefaultCLibrary.class);
	constants = new SolarisConstants();
	break;
    case WindowsIntel32:
    case Other:
    default:
	delegate = (GenericCLibrary) Native.loadLibrary("c", DefaultCLibrary.class);
	constants = new DefaultConstants();
	break;
}
   }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:CLibrary.java

示例2: while

import com.sun.jna.Native; //導入方法依賴的package包/類
/**
 * Finds the given process in the process list.
 *
 * @param processEntry The process entry.
 * @param filenamePattern pattern matching the filename of the process.
 * @return The found process entry.
 */
public static boolean findProcessEntry
                (final Tlhelp32.PROCESSENTRY32.ByReference processEntry,
                 final Pattern filenamePattern) {
    Kernel32 kernel32 = Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS);

    WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0));

    boolean found = false;

    try {
        while (kernel32.Process32Next(snapshot, processEntry)) {
            String fname = Native.toString(processEntry.szExeFile);

            if (fname != null && filenamePattern.matcher(fname).matches()) {
                found = true;
                break;
            }
        }
    } finally {
        kernel32.CloseHandle(snapshot);
    }

    return found;
}
 
開發者ID:mmarquee,項目名稱:ui-automation,代碼行數:32,代碼來源:Utils.java

示例3: OdsDll

import com.sun.jna.Native; //導入方法依賴的package包/類
public OdsDll(String nativeDllPath) {

		if (dllYetToBeInitialized) {

			String actualNativeDllPath = "ods";
			if (nativeDllPath != null) {
				File nativeDllFileOrDir = new File(nativeDllPath);
				if (!nativeDllFileOrDir.exists()) {
					throw new RuntimeException("Invalid native DLL path: " + nativeDllFileOrDir.getAbsolutePath());
				}
				if (nativeDllFileOrDir.isDirectory()) {
					actualNativeDllPath = nativeDllPath + "/ods";
				} else {
					actualNativeDllPath = nativeDllPath;
					for (String ext : new String[]{ ".so", ".dll" }) {
						if (actualNativeDllPath.toLowerCase().endsWith(ext))
							actualNativeDllPath = actualNativeDllPath.substring(
									0, actualNativeDllPath.length() - ext.length());
					}
				}
			}

			// Delft3D-Flow uses ifort for both linux and windows.
			// If in the future another compiler is needed, e.g. gfortran,
			// see org.openda.model_efdc_dll.EfdcDLL for an example of function name mapping.
			if(BBUtils.RUNNING_ON_WINDOWS){
				odsWinIfortDll = (OdsWinIfortDll) Native.loadLibrary(actualNativeDllPath, OdsWinIfortDll.class);

			}else{
				// GfortranFunctionMapper gFortranMapper = new GfortranFunctionMapper();
				// HashMap<String, String> gFortranMap = gFortranMapper.getMap();
				odsWinIfortDll = (OdsWinIfortDll) Native.loadLibrary(
						actualNativeDllPath, OdsWinIfortDll.class); // , gFortranMap);
			}
			dllYetToBeInitialized = true;
		}
	}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:38,代碼來源:OdsDll.java

示例4: deploy

import com.sun.jna.Native; //導入方法依賴的package包/類
/**
 * Deploys WinDivert DLL and SYS files based upon Platform architecture (32/64bit).
 *
 * @param deployDirManager The TemporaryDirManager to create the temp directory where to store the files.
 * @return The {@link WinDivertDLL} instance to use.
 */
public static WinDivertDLL deploy(TemporaryDirManager deployDirManager) {
    String jnaLibraryPath = System.getProperty("jna.library.path");
    try {
        File temp = deployDirManager.createTempDir();
        if (temp != null && temp.delete() && temp.mkdir()) {
            System.setProperty("jna.library.path", deployInTempDir(temp));
            return (WinDivertDLL) Native.loadLibrary(Platform.is64Bit() ? "WinDivert64" : "WinDivert32", WinDivertDLL.class);
        } else {
            throw new IOException("Could not create a proper temp dir");
        }
    } catch (Exception e) {
        throw new ExceptionInInitializerError(new Exception("Unable to deploy WinDivert", e));
    } finally {
        if (jnaLibraryPath != null)
            System.setProperty("jna.library.path", jnaLibraryPath);
    }
}
 
開發者ID:ffalcinelli,項目名稱:jdivert,代碼行數:24,代碼來源:DeployHandler.java

示例5: Capstone

import com.sun.jna.Native; //導入方法依賴的package包/類
public Capstone(int arch, int mode) {
   cs = (CS)Native.loadLibrary("capstone", CS.class);
   int version = cs.cs_version(null, null);
   if (version != (CS_API_MAJOR << 8) + CS_API_MINOR) {
     throw new RuntimeException("Different API version between core & binding (CS_ERR_VERSION)");
   }

   this.arch = arch;
   this.mode = mode;
   ns = new NativeStruct();
   ns.handleRef = new NativeLongByReference();
   if (cs.cs_open(arch, mode, ns.handleRef) != CS_ERR_OK) {
     throw new RuntimeException("ERROR: Wrong arch or mode");
   }
   ns.csh = ns.handleRef.getValue();
   this.detail = CS_OPT_OFF;
this.diet = cs.cs_support(CS_SUPPORT_DIET);
 }
 
開發者ID:binarybird,項目名稱:Redress-Disassembler,代碼行數:19,代碼來源:Capstone.java

示例6: loadDynamicLibrary

import com.sun.jna.Native; //導入方法依賴的package包/類
private CSensors loadDynamicLibrary() {
	Object jnaProxy;

	try {
		jnaProxy = Native.loadLibrary("sensors", CSensors.class);
	} catch (UnsatisfiedLinkError err) {
		LOGGER.info("Cannot find library in system, using embedded one");
		try {
			String libPath = SensorsUtils.generateLibTmpPath("/lib/linux/", "libsensors.so.4.4.0");
			jnaProxy = Native.loadLibrary(libPath, CSensors.class);
			new File(libPath).delete();
		} catch (UnsatisfiedLinkError err1) {
			jnaProxy = null;
			LOGGER.error("Cannot load sensors dinamic library", err1);
		}
	}

	return (CSensors) jnaProxy;
}
 
開發者ID:profesorfalken,項目名稱:jSensors,代碼行數:20,代碼來源:UnixSensorsManager.java

示例7: initialise

import com.sun.jna.Native; //導入方法依賴的package包/類
@PostConstruct
public void initialise() {
    log.info("Initialising NativeManager");

    // Make sure the native directory exists
    File nativeDirectory = settingsManager.getFileFromConfigDirectory("native");

    if (!nativeDirectory.exists()) {
        nativeDirectory.mkdirs();
    }

    // Copy any native libraries to the config directory and load them
    if (settingsManager.getOsType() == OsType.OSX) {
        try {
            String userNotifications = "/native/NsUserNotificationsBridge.dylib";
            File userNotificationsFile = settingsManager.getFileFromConfigDirectory(userNotifications);
            Files.copy(getClass().getResourceAsStream(userNotifications), userNotificationsFile.toPath(),
                StandardCopyOption.REPLACE_EXISTING);

            nsUserNotificationsBridge = (NsUserNotificationsBridge)Native
                .loadLibrary(userNotificationsFile.getAbsolutePath(), NsUserNotificationsBridge.class);
        } catch (Throwable t) {
            log.error("Error loading native notifications bridge", t);
        }
    }
}
 
開發者ID:mpcontracting,項目名稱:rpmjukebox,代碼行數:27,代碼來源:NativeManager.java

示例8: main

import com.sun.jna.Native; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
	//long lib = JTranscFFI.Loader.dlopen("kernel32.dll");
	//System.out.println(lib);
	//long SleepAddr = JTranscFFI.Loader.dlsym(lib, "Sleep");
	//System.out.println(SleepAddr);

	//SDL2 sdl2 = (SDL2) Native.loadLibrary("sdl2", SDL2.class);
	//sdl2.SDL_Init(SDL2.SDL_INIT_VIDEO);
	//sdl2.SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL2.SDL_WINDOW_SHOWN);
	////Pointer.createConstant(10).getNativeLong()

	//Thread.sleep(1000L);

	if (JTranscSystem.isWindows()) {
		Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
		User32 user32 = (User32) Native.loadLibrary("user32", User32.class);
		for (int n = 0; n < 6; n++) {
			kernel32.Beep(698 * (n + 1), 300);
			kernel32.Sleep(100);
		}
		user32.MessageBoxA(0, "done!", "done!", 0);
	} else {
		System.out.println("This demo just works on windows!");
	}
}
 
開發者ID:jtransc,項目名稱:jtransc,代碼行數:26,代碼來源:BeepExample.java

示例9: LibNotifyWrapper

import com.sun.jna.Native; //導入方法依賴的package包/類
private LibNotifyWrapper() {
  myLibNotify = (LibNotify)Native.loadLibrary("libnotify.so.4", LibNotify.class);

  String appName = ApplicationNamesInfo.getInstance().getProductName();
  if (myLibNotify.notify_init(appName) == 0) {
    throw new IllegalStateException("notify_init failed");
  }

  String icon = AppUIUtil.findIcon(PathManager.getBinPath());
  myIcon = icon != null ? icon : "dialog-information";

  MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
  connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() {
    @Override
    public void appClosing() {
      synchronized (myLock) {
        myDisposed = true;
        myLibNotify.notify_uninit();
      }
    }
  });
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:LibNotifyWrapper.java

示例10: restartOnWindows

import com.sun.jna.Native; //導入方法依賴的package包/類
private static void restartOnWindows(@NotNull final String... beforeRestart) throws IOException {
  Kernel32 kernel32 = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class);
  Shell32 shell32 = (Shell32)Native.loadLibrary("shell32", Shell32.class);

  final int pid = kernel32.GetCurrentProcessId();
  final IntByReference argc = new IntByReference();
  Pointer argv_ptr = shell32.CommandLineToArgvW(kernel32.GetCommandLineW(), argc);
  final String[] argv = argv_ptr.getStringArray(0, argc.getValue(), true);
  kernel32.LocalFree(argv_ptr);

  doScheduleRestart(new File(PathManager.getBinPath(), "restarter.exe"), new Consumer<List<String>>() {
    @Override
    public void consume(List<String> commands) {
      Collections.addAll(commands, String.valueOf(pid), String.valueOf(beforeRestart.length));
      Collections.addAll(commands, beforeRestart);
      Collections.addAll(commands, String.valueOf(argc.getValue()));
      Collections.addAll(commands, argv);
    }
  });

  // Since the process ID is passed through the command line, we want to make sure that we don't exit before the "restarter"
  // process has a chance to open the handle to our process, and that it doesn't wait for the termination of an unrelated
  // process which happened to have the same process ID.
  TimeoutUtil.sleep(500);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:Restarter.java

示例11: load

import com.sun.jna.Native; //導入方法依賴的package包/類
@SuppressWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
private static Object load(Map<String,?> options) {
    try {
        return Native.loadLibrary(GENERIC, GnomeKeyringLibrary.class, options);
    } catch (UnsatisfiedLinkError x) {
        // #203735: on Oneiric, may have trouble finding right lib.
        // Precise is using multiarch (#211401) which should work automatically using JNA 3.4+ (#211403).
        // Unclear if this workaround is still needed for Oneiric with 3.4, but seems harmless to leave it in for now.
        if (new File(EXPLICIT_ONEIRIC).isFile()) {
            return Native.loadLibrary(EXPLICIT_ONEIRIC, GnomeKeyringLibrary.class, options);
        } else {
            throw x;
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:GnomeKeyringLibrary.java

示例12: initialize

import com.sun.jna.Native; //導入方法依賴的package包/類
/**
 * Initialize the wdm library.
 *
 * @param wdmDllPath Full path specification of the native DLL.
 */
public static void initialize(File wdmDllPath) {

    // Initialize the DLL, if not done yet
    if (dllYetToBeInitialized) {
        Results.putMessage(WdmDll.class.getSimpleName() + ": initializing wdm dll " + wdmDllPath.getAbsolutePath());

        String nativeDllPath = wdmDllPath.getAbsolutePath();
        File nativeDll = new File(nativeDllPath);
        if (!nativeDll.exists()) {
            throw new RuntimeException("WdmDll: Native DLL/SO does not exist: " + wdmDllPath.getAbsolutePath());
        }

        if(BBUtils.RUNNING_ON_WINDOWS) {
            nativeDLL = (IWdmFortranNativeDLL) Native.loadLibrary(nativeDllPath, IWdmFortranNativeDLL.class);
        } else {
        	// For now assumes that gfortran is used for linux and ifort for windows
        	GfortranWdmFunctionMapper gfortranMapper = new GfortranWdmFunctionMapper();
        	HashMap<String, String> gfortranMap = gfortranMapper.getMap();
            nativeDLL = (IWdmFortranNativeDLL) Native.loadLibrary(nativeDllPath, IWdmFortranNativeDLL.class, gfortranMap);
        }

        dllYetToBeInitialized = false;

        Results.putMessage(WdmDll.class.getSimpleName() + ": wdm dll initialized.");
    }
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:32,代碼來源:WdmDll.java

示例13: loadDLL

import com.sun.jna.Native; //導入方法依賴的package包/類
static void loadDLL(D3dFlowModelConfig.DllType platform, String nativeDllPath) {
	D3dFlowDll.platform = platform;
	if (platform == D3dFlowModelConfig.DllType.win32_ifort) {
		if (!dllHasBeenLoaded) {
			String nativeDllName = new File(nativeDllPath).getName();
			File nativeDllDir = new File(nativeDllPath).getParentFile();
			File[] filesInDllDir = nativeDllDir.listFiles();
			if (filesInDllDir == null) {
				throw new RuntimeException("error in initialize: no files in DLL dir");
			}
			for (File file : filesInDllDir) {
				String fileName = file.getName();
				if (fileName.toLowerCase().endsWith(".dll") &&
						!(fileName.equalsIgnoreCase(nativeDllName)) &&
						!(fileName.toLowerCase().contains("libpollute2d")) &&
						!(fileName.toLowerCase().contains("jep")) &&
						!(fileName.toLowerCase().contains("mpich")) &&
						!(fileName.equalsIgnoreCase("dlwqlib.dll"))
						){
					// dependent dll, load it.
					//System.out.println("loading dependent dll: "+fileName+"\n");
					Native.loadLibrary(file.getAbsolutePath(), IDummyDll.class);
				}
			}
			winIfortDll = (D3dFlowWinIfortDll) Native.loadLibrary(nativeDllPath, D3dFlowWinIfortDll.class);
			dllHasBeenLoaded = true;
		}
	} else if (platform == D3dFlowModelConfig.DllType.linux64_gnu) {
		linuxGnuDll = (D3dFlowLinuxGnuDll) Native.loadLibrary(nativeDllPath, D3dFlowLinuxGnuDll.class);
	} else {
		throw new RuntimeException("loadDLL: DLL/so type not known");
	}
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:34,代碼來源:D3dFlowDll.java

示例14: initVideoImportEngine

import com.sun.jna.Native; //導入方法依賴的package包/類
@Override
public void initVideoImportEngine(Optional<String> pathToLibrary) {
	if (pathToLibrary.isPresent()) {
		log.debug("Path to library {}", pathToLibrary);
		NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), pathToLibrary.get());
		Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
		log.debug("Library loaded");
	}
}
 
開發者ID:KodeMunkie,項目名稱:imagetozxspec,代碼行數:10,代碼來源:VLCVideoImportEngine.java

示例15: main

import com.sun.jna.Native; //導入方法依賴的package包/類
public static void main(String args[]) throws InterruptedException {
    Pointer pointer;
    System.out.println("running in " + System.getProperty("sun.arch.data.model"));

    System.out.println("Loading dll");
    autoHotKeyDll lib = (autoHotKeyDll) Native.loadLibrary("AutoHotkey.dll", autoHotKeyDll.class);

    System.out.println("initialisation");
    lib.ahktextdll(new WString(""), new WString(""), new WString(""));
    // Thread.sleep(100);
    // lib.addFile(new WString(System.getProperty("user.dir") + "\\lib.ahk"), 1);
    // Thread.sleep(1000);

    // System.out.println("function call");
    // System.out.println("return:" + lib.ahkFunction(new WString("function"),new WString(""),new WString(""),new
    // WString(""),new WString(""),new WString(""),new WString(""),new WString(""),new WString(""),new
    // WString(""),new WString("")).getString(0));
    Thread.sleep(1000);

    System.out.println("displaying cbBox");
    lib.ahkExec(new WString("Send {Right}"));
    Thread.sleep(1000);
}
 
開發者ID:SlideKB,項目名稱:SlideBar,代碼行數:24,代碼來源:AHKTest.java


注:本文中的com.sun.jna.Native.loadLibrary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。