I'm trying to use Elasticsearch in Java. I hava Elasticserach version 7.0.1 installed.
The following line:
import org.elasticsearch.transport.client.*;
produces the compilation error:
The import org.elasticsearch.transport.client cannot be resolved
Even though I can see that this is the correct path in the source code.
pom.xml:
<project xmlns="...">
...
<dependencies>
...
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.0.1</version>
</dependency>
</dependencies>
</prpject>
You have to use the below dependency for transport client.
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>7.0.1</version>
</dependency>
Looking at the source code , That package has just one class. It will be conventional to use the specific path instead of calling all.
You may want to twitch your import to
import org.elasticsearch.transport.client.PreBuiltTransportClient;
Your dependency in the pom.xml:
<project xmlns="...">
...
<dependencies>
...
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>7.0.1</version>
</dependency>
</dependencies>
</project>
That should resolve it.
Always refer to your build repository online to be sure you are correctly defining the latest version of your dependency.
Related
I have the following dependency declared in my pom.xml file
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.2.0</version>
</dependency>
I'm working in Intellij and it says it's not found. It also won't let me import anything from the com.itextpdf packages.
I've tried a couple clean builds and restarts with no change. I also tried adding the itextpdf repository to the POM file with no change.
it is
<!-- https://mvnrepository.com/artifact/com.itextpdf/itext7-core -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.2.0</version>
<type>pom</type>
</dependency>
I am working on my first project with Java restful web services, but I am running into some issues. When I run the server with Tomcat and type the URL of the GET service, I get an HTTP Status 500 – Internal Server Error. I did the research for hours but cannot find anything. Maybe there is some issue in the pom.xml.
Below is some code:
ResourceConfig:
package nl.hu.bep.IPASS.Config;
import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
#ApplicationPath("/restservices")
public class JerseyConfig extends ResourceConfig {
public JerseyConfig(){
packages("nl.hu.bep.IPASS.webservices");
}
}
Resource code:
import nl.hu.bep.IPASS.model.Product;
import nl.hu.bep.IPASS.model.ProductBeheer;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
#Path("/producten")
public class ProductResource {
#GET
#Produces("application/json")
public Response getProducten(){
ProductBeheer beheer = ProductBeheer.getInstance();
return Response.ok(beheer.getAlleProducten()).build();
}
pom.xml:
<?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>nl.hu.bep.IPASS</groupId>
<artifactId>SD_IPASS_2021</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>SD_IPASS_2021</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.20</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.6.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</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-war-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
error:
Screenshot Error
Can someone help me, please?
I also got same erorr while building android release apk for my flutter project , I resolved this by adding :
android.jetifier.blacklist=bcprov-jdk15on
in gradle.properties file and rebuild the project and it worked for me.
If this work for you that's good else you can refer to this issue on github here and this.
You've made class files that cannot be read by JDK14 and downwards; you need at least JDK15. That's what '59' means (it's the class file format version emitted by JDK15).
You have two options:
Downgrade
<maven.compiler.source>15</maven.compiler.source> - make this a lower version, at least as low as the version of the JDK you installed on your server.
Upgrade
Upgrade your server to run JDK15 or up. Specifically, when you run your tomcat, somewhere, somehow, the java executable is run. That needs to be JDK15 (you can install multiple JDKs on one system - that's fine, but the one used to run tomcat needs to be 15 or up).
How I fixed this issue, using a mac, clicking on Android Studio on the top left corner of your screen, then click on Preferences
Click on Build, Execution, Deployment, click on Build Tools and select Gradle.
Where you see Gradle JDK, click the drop-down and select any Embedded JDK lower than 15, in this example, I used 11.0.13.
Then click on Apply, and Ok.
You should be good now. 👏
I'm trying to upgrade an application to Java 11.0.2, from Java 8. So those are my very first steps with Jigsaw modules!
My application uses Guice, and the Assistedinject, and Throwingproviders extensions.
Here's my current module-info.java:
`
module com.example.mymodule {
requires com.google.guice;
requires com.google.guice.extensions.assistedinject;
requires com.google.guice.extensions.throwingproviders;
//...
}
`
The application is based on Maven and when I run mvn package I get no error. But In Eclipse (2018-12), I have this error "`The package com.google.inject is accessible from more than one module":
I tried commenting each of the required module in module-info.java but I clearly need the three of them.
Is there something I can do to remove this error? Or is this an Eclipse bug?
Here's my pom.xml:
<?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>example</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.7</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.7</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-throwingproviders</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
<version>4.2.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
</plugins>
</build>
</project>
Here is a minimal project to reproduce my error.
And here's a video of the issue (to be watched in 1080P for clarity!).
Eclipse uses its own compiler which is even stricter than javac in following the specs. You are requiring different Modules/Jars in your module-info which are all using the package com.google.inject. This is some kind of a split package situation which is not allowed in the JPMS spec. AFAIK javac only yields an error if there are actual classes in the same packages of different moduls, but the eclipse compiler is even more picky here.
There are some solutions out there for solving split package problems. If you don't find a newer version of the libs where the problem is solved (which unfortunately is not very likely for most dependencies today) you could f.e. merge the modules into one custom modules, but this is not a perfect solution of course.
For more background information on the issue see also
Eclipse can't find XML related classes after switching build path to JDK 10 and https://bugs.openjdk.java.net/browse/JDK-8215739
I can reproduce the error on my machine (same Eclipse version, OpenJDK 11), works fine on Apache NetBeans IDE 10.0.
Seems to be a bug in Eclipse, you should file it here. You already have a minimal project that reproduces the error, that helps a lot.
Your test project already works in RC2 of 4.11 (which will be released on March 20, 2019)
You can download the release candidate at https://download.eclipse.org/eclipse/downloads/drops4/S-4.11RC2-201903070500/
Better way to deal with this kind of problem by just go to dependencies hierarchy in pom.xml, where you can find duplicate jar, sometimes it could be difficult to find duplicate jar as jar itself have pom dependencies and "Dependencies hierarchy" will help you to deal with maven problem
`
All
I am running into this error in my project when I updated aws library to the latest 1.11.3.
Caused by:
java.lang.NoClassDefFoundError: org/apache/http/conn/SchemePortResolver
at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.<init>(ApacheHttpClientFactory.java:40)
at com.amazonaws.http.AmazonHttpClient.<clinit>(AmazonHttpClient.java:97)
at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:145)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:393)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:373)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:355)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:339)
in my pom.xml
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-kms</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-ext-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-encryption-sdk-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Anyone know what I did wrong?
thanks
I had a similar issue with my grails application. In my case the ClassNotFoundException was being thrown from a deploy script. For me the reason SchemePortResolver wasn't being resolved implicitly was because it wasn't required at compile time, it was needed at runtime. Here's what I added to my BuildConfig.groovy to fix it:
runtime 'org.apache.httpcomponents:httpclient:4.5.2' //Required by BeanstalkDeploy.groovy at runtime
Since the OP's question was for Maven, here's the equivalent include:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
<scope>runtime</scope>
</dependency>
If you add,
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
,it should work ok as it contains the missing class definitions.
A common cause would be a Maven dependency conflict. In the example below (pom.xml as viewed in Eclipse's Dependency Hierarchy tab), the POM explicitly includes v4.1 of httpclient, which forces Maven to omit the v4.5.5 that aws-java-sdk-core requires (and thus, causes the similar error java.lang.NoClassDefFoundError: org/apache/http/conn/DnsResolver at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory...):
In my case I delete the .meta file in eclipse workplace then import the project again thereafter it work like a charm.
Could not know where the problem exactly.
Before delete .meta I add all files from
aws-java-sdk-1.11.606\third-party\lib
My java program embeds the maven 3.0.5 and aether 1.13.1 libraries,
and I use it as follows:
ProjectBuildingResult projectBuildingResult =
projectBuilder.build(myArtifact, projectBuildingRequest);
all the properties used in the pom file, such as ${spring.version} in here,
get resolved successfully.
<project>
<groupId>my_group</groupId>
<artifactId>my_artifact1</artifactId>
<version>2.3.0-SNAPSHOT</version>
<properties>
<spring.version>3.1.4.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>my_group</groupId>
<artifactId>my_artifact2</artifactId>
<version>${project.artifact.selectedVersion.majorVersion}</version>
</dependency>
</dependencies>
</project>
that is,
projectBuildingResult.getProject().getDependencies().get(0).getVersion()
returns "3.1.4.RELEASE" instead of "${spring.version}", as expected.
however, the property ${project.artifact.selectedVersion.majorVersion} does
not get resolved,
so
projectBuildingResult.getProject().getDependencies().get(1).getVersion()
returns "${project.artifact.selectedVersion.majorVersion}" instead of "2".
why is that?
how to get this resolved?