1

i'm quite sure i have everything right but it just won't compile the example posted on the website

Here's my 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>

and here's the error output from 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

Here's my github if you want to have a go at it. Find the file GlobalKeyListenerExample.java and try to compile it.

jorma uotinen
  • 15
  • 1
  • 3
  • You dont have jnativehook listed as a dependency in your POM. e.g com.1stleg jnativehook 2.1.0 – JJF Mar 12 '20 at 17:28
  • but it is there? just below modelversion. or is it at the wrong place? – jorma uotinen Mar 12 '20 at 17:34
  • That's not your pom. That's the pom for the jnativehook project itself. It's defining what jnativehook is, not using it as a dependency. Your pom should look more link the answer I'll post below – JJF Mar 12 '20 at 18:09

1 Answers1

1

You don't have jnativehook listed as a dependency. The pom you listed is not the pom you should be using for your project, that's the pom that defines the artifact you're trying to use. Your pom should look more like this:

<?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>
JJF
  • 2,681
  • 2
  • 18
  • 31
  • i copied that to my POM and when i ran the maven tests it gave this error: java: lambda expressions are not supported in -source 7 well, i went to project structure>modules>sources and changed it from 7 to 11 and it still persists. or am i supposed to change some fields in that POM you pasted? – jorma uotinen Mar 13 '20 at 06:54