当前位置: 首页>>代码示例>>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;未经允许,请勿转载。