java - 如何在intellij上正确编译jnativehook?

标签 java intellij-idea jnativehook

我很确定我一切都正确,但它只是无法编译 website 上发布的示例

这是我的 POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>com.1stleg</groupId>
<artifactId>jnativehook</artifactId>
<version>2.1.0</version>
<name>JNativeHook</name>

<description>Global keyboard and mouse listeners for Java.</description>
<url>https://github.com/kwhat/jnativehook</url>
<licenses>
    <license>
        <name>GNU General Public License (GPL), Version 3.0</name>
        <url>https://www.gnu.org/licenses/gpl-3.0.txt</url>
    </license>
    <license>
        <name>GNU Lesser General Public License (LGPL), Version 3.0</name>
        <url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
    </license>
</licenses>
<developers>
    <developer>
        <name>Alexander Barker</name>
        <email>alex@1stleg.com</email>
        <organization>Personal</organization>
        <organizationUrl>https://github.com/kwhat/</organizationUrl>
    </developer>
</developers>
<scm>
    <connection>scm:git:git@github.com:kwhat/jnativehook.git</connection>
    <developerConnection>scm:git:git@github.com:kwhat/jnativehook.git</developerConnection>
    <url>git@github.com:kwhat/jnativehook.git</url>
</scm>

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>12</release> </configuration> </plugin> </plugins> </build>

这是 cmd 的错误输出:

PS C:\Users\XXX\IdeaProjects\Defa_Kalenteri\src\main\java> javac -classpath ./JNativeHook.jar 
GlobalKeyListenerExample.java
GlobalKeyListenerExample.java:2: error: package org.jnativehook does not exist
import org.jnativehook.GlobalScreen;
                  ^
GlobalKeyListenerExample.java:3: error: package org.jnativehook does not exist
import org.jnativehook.NativeHookException;
                  ^
GlobalKeyListenerExample.java:4: error: package org.jnativehook.keyboard does not exist
import org.jnativehook.keyboard.NativeKeyEvent;
                           ^
GlobalKeyListenerExample.java:5: error: package org.jnativehook.keyboard does not exist
import org.jnativehook.keyboard.NativeKeyListener

这是我的 github如果你想尝试一下。找到文件 GlobalKeyListenerExample.java 并尝试编译它。

最佳答案

您没有将 jnativehook 列为依赖项。您列出的 pom 不是您应该在项目中使用的 pom,而是定义您尝试使用的工件的 pom。你的 pom 应该看起来更像这样:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>someartifact</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>someartifact</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.1stleg</groupId>
      <artifactId>jnativehook</artifactId>
      <version>2.1.0</version>
    </dependency>
  </dependencies>


  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

关于java - 如何在intellij上正确编译jnativehook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60659025/

相关文章:

java - ActiveMQ 在 Spring Boot 中延迟传递消息

java - 调试java代码时出现警告

java - 无法运行代码,intellij run arrow是 'grey'

intellij-idea - IntelliJ 中 Kotlin 代码的大量编译时间

java - 使用 JNativeHook 制作游戏

java - 当使用 throws 关键字调用 void 时,所有抛出的错误都适用于我调用 void 的地方

java - 如何在生产服务器上使用 java 在新窗口中打开 URL

java - 使用可选对象字段返回空对象或新对象

java - 不重置版本号的最后一位是否有意义

java - 使用 JNativeHook 仅读取每个按键一次