如何在窗口10上构建jnativehook

时间:2017-08-18 02:16:12

标签: jnativehook

我在我的程序中使用jnativehook。我编辑源代码很少,它在mac上运行良好。 但是当它在窗口上执行时,我收到了这个错误。

    8월 18, 2017 10:47:48 오전 org.jnativehook.DefaultLibraryLocator getLibraries
심각: Unable to extract the nativelibrary /org/jnativehook/lib/windows/x86_64/JNativeHook.dll!

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: org.jnativehook.GlobalScreen.getAutoRepeatRate()Ljava/lang/Integer;
at org.jnativehook.GlobalScreen.getAutoRepeatRate(Native Method)
at org.jnativehook.GlobalScreen.<clinit>(Unknown Source)
at SmiPlayer.Main.main(Main.java:75)
... 11 more
Exception running application SmiPlayer.Main

所以我试着在Window上构建它。我设置了JAVA_HOME路径并添加了JNITasks。 但我收到了这条消息。

    BUILD FAILED
    C:\jnativehook-2.1.0\build.xml:345: Execute failed: java.io.IOException: Cannot run program "sh" (in directory "C:\jnativehook-2.1.0\src\libuiohook"): CreateProcess error=2

我也尝试过cross.build.xml,但我认为这个错误。

BUILD FAILED
C:\jnativehook-2.1.0\cross.build.xml:160: The following error occurred while executing this line:
C:\jnativehook-2.1.0\jnitasks\build.xml:76: Compile failed; see the compiler error output for details.

第160行是下面代码块的第5行              编译JNITasks源代码......         

    <ant antfile="${basedir}/jnitasks/build.xml" dir="${basedir}/jnitasks">
        <target name="compile" />
        <target name="jar" />

        <!-- We need to override the src and bin locations. -->
        <property name="dir.bin" value="${basedir}/jnitasks/bin" />
        <property name="dir.src" value="${basedir}/jnitasks/src" />
        <property name="dir.jar" value="${basedir}" />

        <!-- Set a few of the configurable properties. -->
        <property name="ant.build.debug" value="${ant.build.debug}" />
        <property name="ant.build.javac.compiler" value="${ant.build.javac.compiler}" />
        <property name="ant.build.javac.source" value="${ant.build.javac.source}" />
        <property name="ant.build.javac.target" value="${ant.build.javac.target}" />
        <property name="ant.build.javac.args" value="${ant.build.javac.args}" />
    </ant>
</target>

和第76行是下面代码块的第8行                                                                                                      

    <condition property="ant.build.javac.bootclasspath" value="${env.JDK_HOME}/bundle/Classes/classes.jar">
        <available file="${env.JDK_HOME}/bundle/Classes/classes.jar" type="dir" />
    </condition>
    <condition property="ant.build.javac.bootclasspath" value="${env.JAVA_HOME}/bundle/Classes/classes.jar">
        <available file="${env.JAVA_HOME}/bundle/Classes/classes.jar" type="dir" />
    </condition>
    <condition property="ant.build.javac.bootclasspath" value="${java.home}/bundle/Classes/classes.jar">
        <available file="${java.home}/bundle/Classes/classes.jar" type="file" />
    </condition>

    <fail message="Could not determine ant.build.javac.bootclasspath location.  Please set your JDK_HOME / JAVA_HOME environment variable or manually set the ant.build.javac.bootclasspath property to the location of your rt.jar file.">

我还没在mac上尝试过cross.build.xml。

我需要一些帮助..

1 个答案:

答案 0 :(得分:0)

您必须为每个平台单独编译所有本机代码。没有像msys2这样的交叉编译器,你无法在Mac上编译Windows。您可以使用ant compile-native在每个平台上编译一组二进制文件,并在调用ant jar之前组合lib目录。 cross.build.xml文件用于交叉编译linux中的所有平台。关于交叉编译的说明也位于Wiki中。

您的Windows 10版本失败,因为您没有使用正确的shell进行编译。您必须使用mingw32 / 64 shell来运行ant。同样,这在项目页面的Wiki中都有概述。