2

我在我的程序上使用 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。

我需要一些帮助..

4

1 回答 1

0

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

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

于 2017-08-18T18:10:58.813 回答