Maven doesn't compile the project with jNativeHook from Github - java

I have added Jitpack repo and dependency from Github to pom.xml and it still doesn't compile. However, when I point onto the line in import block, it clearly shows the description of a module.
VSCode screenshot
For example, I try to import com.github.kwhat.jnativehook.GlobalScreen, it shows the description of the module but still underlines the line with red and shows the error:
The type com.github.kwhat.jnativehook.GlobalScreen is not accessible Java(16778666)
What could be the problem?
Here's a part of pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>com.github.kwhat</groupId>
<artifactId>jnativehook</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>

Just try to synchronize you project.
I add an imagine where can be seen that dependencies is load correctly..

Related

Netbeans Maven Failed to execute goal on project

I am working on a java project currently, my problem is a bit weird as yesterday my code was working fine then suddenly today when I try to build and test my code I get this error:
Failed to execute goal on project extraportGlobalSearch: Could not resolve dependencies for project com.api:extraportGlobalSearch:jar:1.0: Failed to collect dependencies for [org.glassfish.jersey.containers:jersey-container-grizzly2-http:jar:2.27 (compile), org.glassfish.jersey.inject:jersey-hk2:jar:2.27 (compile), junit:junit:jar:4.9 (test), com.googlecode.json-simple:json-simple:jar:1.1.1 (compile), com.fasterxml.jackson.core:jackson-annotations:jar:2.5.4 (compile), javax.servlet:javax.servlet-api:jar:3.0.1 (compile), com.google.zxing:core:jar:3.3.3 (compile), com.fasterxml.jackson.core:jackson-databind:jar:2.5.4 (compile), oracle:ojdbc:jar:11.2.0.4 (compile), org.glassfish.grizzly:grizzly-http-server:jar:2.4.0 (compile)]: Failed to read artifact descriptor for oracle:ojdbc:jar:11.2.0.4: Could not transfer artifact oracle:ojdbc:pom:11.2.0.4 from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/oracle/ojdbc/11.2.0.4/ojdbc-11.2.0.4.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
I tried to add another repo using https://repo.maven.apache.org/maven2/ url in my pom.xml but the error still persist. I have tried to resolve this for the past 5 hours, it would be great if anyone can help me, here is my pom.xml:
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.api </groupId>
<artifactId>extraportGlobalSearch</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>extraportGlobalSearch</name>
<repositories>
<repository>
<id>apache2-https</id>
<name>Apache 2 https</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<!-- uncomment this to get JSON support:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.4</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.4</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.2.0.4</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server</artifactId>
<version>2.4.0</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.api.GlobalSearch.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<jersey.version>2.27</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Help needed. Thanks in advance.
<packaging>jar</packaging>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
The issue is related to maven moving to https only: https://blog.sonatype.com/central-repository-moving-to-https
I have found that my problem was that Netbeans (8.2) was set to use the bundled maven executable (3.0.5). This version of maven is outdated and does not automatically reach for the https repo.
I have a newer version installed (Apache Maven 3.5.4 (Red Hat 3.5.4-5)
) that worked by executing mvn clean install in my project's directory.
To get Netbeans to use a different version of maven you can go to Tools->Options->Java->Maven and in Maven Home point to where your maven installation is located. For me it was /usr/bin/mvn and I had to define the path as just /usr as it seems that Netbeans expects to find a directory named bin containing the mvn executable.
Also, related to maven moving repositories, for certain old dependencies I had to use the now insecure endpoint in my maven config:
<pluginRepository>
<id>Codehaus repository</id>
<url>http://insecure.repo1.maven.org/maven2/</url>
</pluginRepository>
Just adding this in case it is useful to anyone.
You should update your maven version, the last maven version use https.
Download maven https://maven.apache.org/download.cgi (binary zip file) and extract it.
In netbeans, go to Tools -> Options -> Java -> Maven. In Maven Home select Browse, and select the folder where you extract maven
Enjoy it!
While the other responses give you workarounds by manually configuring the repository or a more recent version of Maven, the true source of the problem is that Netbeans (8.2) has became obsolete and is no more updated, you'd better migrate to Apache Netbeans (currently at version 11.3).
I fixed the issue by updating to latest maven version, it started to use https instead of http to download all the deps.
I changed maven version for global netbeans configuration Tools -> Options -> Java ->Maven ->Maven Home and Browse your maven installation of windows system (for example maven3.6) , i think so maven version embed netbeans 8.2 needs updated

Sikuli Screen constructor giving error :Cannot instatiate the type screen

Sikuli dependency version in maven is:
<dependency>
<groupId>org.sikuli</groupId>
<artifactId>sikuli-api</artifactId>
<version>1.2.0</version>
</dependency>
I am trying to do coding for image comparison using Sikuli API but getting error on:
Screen s =new Screen();
even though Screen() constructor does exist for Screen class in Sikuli.
Please try this instead:
<repositories>
<repository>
<id>snapshot</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
I think what you are using point to another project.
Go to https://jar-download.com/?search_box=sikuli and download the jar.
Create java project and add build path.
Please try the following:
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>2.0.4</version>
</dependency>

EnableEurekaServer import doesn't exist

I build a Spring-Service with gradle and I wanted to use a Eureka-Server with it.
My java-file looks like this:
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
#EnableEurekaServer
public class Welcome {
....
}
but when I try to build it with my gradle-file it says:
org.springframework.cloud.netflix.eureka.server does not exist
I searched for a solution for this problem but I seem to be alone with it. Does someone know why it is not working? Do I have to write something specific into the build.gradle-file?
The following dependency worked for me:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
Assuming you use a bill of materials to manage Spring Cloud dependencies:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Just add the following depedency to your project:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
Spring Cloud releases have names instead of numbers. And you must ensure that Spring Cloud version is compatible with the Spring Boot version you are using. See more details here.
Well if you are using gradle project, just add below dependency to your build.gradle file:
compile('org.springframework.cloud:spring-cloud-netflix-eureka-server')
Specify repository in pom if missing:
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Make sure that you havespring-cloud-starter-netflix-eureka-server added in your pom.xml file
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
Adding this dependency worked for me.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
<version>3.1.2</version>
</dependency>

Missing artifact in maven internal repository

I have added two jar files to my internal repository and created its corresponding folder directory as shown below in image. but it is showing compile time error in my pom.xml where i have added the dependency for both the jars, saying "Missing artifact common:common-jar:jar:1.0" and "Missing artifact mediator:mediator-jar:jar:1.0"
look at my pom.xml below
<properties>
<jdk.version>1.7</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Maven plugin & MOJO versions -->
<version.maven-compiler-plugin>3.1</version.maven-compiler-plugin>
</properties>
<repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${basedir}/libs</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>common</groupId>
<artifactId>common-jar</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>mediator</groupId>
<artifactId>mediator-jar</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
please suggest what to do.
I think there is some problem identifying value for ${basedir} but i have also tried ${project.basedir} as well, it is also not working.
The problem lies in your url tag. Instead of <url>file://${basedir}/libs</url> try removing the double slash before ${basedir}: <url>file:${basedir}/libs</url>
You have a nice guide here if you want to check it.
First : Never use <scope>system</scope>
Follow the Example:
Project folder - C:\UX\X5SCX\GIT_STORE\SRC\FACTOR\fwk\broker\lib
<repositories>
<repository>
<id>local-repo</id>
<url>file://${basedir}/lib</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>ews</groupId>
<artifactId>ews-java-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>

during maven build [mvn install] dependencies not getting downloaded from repository

I am new to pom but went through the "Getting started" on maven.apache.org and also referred to an existing project within the company before i started on this project.
Info:
If i specify the jars as referenced libs in eclipse the project is running smooth and no issues are observed.
Problem: compilation errors since unable to download dependent code from repository.
My project structure is [simplified for easier understanding]
utils
utils/commons [has source in src/main/java style] [uses package org.apache.commons.io.IOUtils]
utils/commons/pom.xml
utils/pom.xml [parent]
Now I began with commons folder to write the pom.xml as the only module and no reference to any parent / other module.
After I ran mvn install it gave errors as
ToolUtils.java:[17,28] error: package org.apache.commons.io does not exist
ToolUtils.java:[18,23] error: package org.apache.log4j does not exist
If i commented the code which was using org.apache.commons.io.IOUtils then the mvn install works fine and generates a jar.
I looked up the net and found that the issue is failing to locate the repository so i updated the reference
to parent pom.xml.
And also included the repositories details in the parent pom.xml. [which is directly under utils folder]
I am still getting the same error and the build does not move further.
ToolUtils.java:[17,28] error: package org.apache.commons.io does not exist
ToolUtils.java:[18,23] error: package org.apache.log4j does not exist
I am using an internal URL which i have verified manually in a broswer.
Also I have verified that the proxy details are correct since another old project refers to the same URL and is getting built properly.
[Unfortunately the project is far too complex to copy paste the pom.xml and modify ,
hence writing the pom.xml from scratch.]
Can some point what am i missing which causes no download from repository ?
Thanks in advance.
Any help would be deeply appreciated.
Note:
1) I am pasting snippets from the 2 different pom.xml with their directory names for easier identification. Attachments can be provided on request.
2) I have modified the references to confidential data across to protect some identities.
utils/common/pom.xml [commons module]
....
<parent>
<groupId>com.osg.rtos</groupId>
<artifactId>rxutils</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
....
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-commons-service</artifactId>
<version>${rtos.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
utils/pom.xml [parent]
....
<groupId>com.osg.rtos</groupId>
<artifactId>rxutils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rxutils</name>
<packaging>pom</packaging>
<repositories>
<repository>
<id>release</id>
<url>http://internal.com/~devbuild/repository</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-commons-service</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-data</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-exception</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-mailbox-service</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-message-service</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-rest</artifactId>
<version>${rtos.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>commons</module>
<module>rxutils</module>
<module>tool</module>
</modules>
...
You need to remove the <dependencyManagement> tags that surround the <dependencies> section in the commons module pom.xml.
The <dependencyManagement> section allows you to specify dependency information, such as version number, in a parent pom (as you have done) so that you can simplify dependencies in the child poms. However, you still need a <dependencies> section to specify what dependencies are required for that child.
in pom.xml use
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
remove or comment <exclusions> and <exclusion>

Categories

Resources