Configure build path problem in eclipse - java - java

I upgraded the elastic search from version 5.5 to 7.7, everything is working as expected.
But when I try to get the Total hits, I get the following error
searchResponse.getHits().getTotalHits()
The type org.apache.lucene.search.TotalHits cannot be resolved. It is indirectly referenced from required .class files
We are not using the lucene library but still, it says it refers to the lucene,
Any help is appreciated to fix this.
Maven pom.xml :
I have only these two Jars,
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>7.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>
Thanks,
Harry

As mentioned this link, you probably need to add the below dependency:
<repository>
<id>elastic-lucene-snapshots</id>
<name>Elastic Lucene Snapshots</name>
<url>https://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
Also as per this link, you may also need to add Log4j dependency as well:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>
That should do the trick.
Alternatively you can also add the below lucene dependency with the exact version you can see if you just do http://<hostname>:9200, however I suggest the above approach and go as per their documentation.
<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-core -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>8.5.1</version>
</dependency>
Hope that helps!

Related

Update version of child dependency in pom.xml

In my spring boot application, I'm using log4j2.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
Which is by default picking up version -
<version>2.1.6.RELEASE</version>
This version of log4j2 internally uses log4j:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.2</version>
<scope>compile</scope>
</dependency>
Recently it has been announced - log4j has some serious vulnerabilities till version 2.16.
Also no version of log4j2 till now uses safer version - 2.17 of log4j.
So I want to first try to update my pom to use 2.17 version of log4j without changing parent log4j2 version.
I know it might not work & might give compilation issues, but I still want to try it first.
How can I do that?
I would suggest to define log4j via bom file like this:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>2.17.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
You can use <dependencyManagement>:
<dependencyManagement>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>[2.17.0,)</version>
</dependency>
</dependencyManagement>
This configures the dependency log4j-core (if it exists) to use version 2.17 or later (see Version Range References).
Put the dependencyManagement section next to your dependencies section.
If you navigate to parent pom.xml(s), you will see spring-boot-dependencies-2.x.x.pom and find following dependency definition.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>${log4j2.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
So, the version can be overriden and just define your version in your pom.xml as follows.
<properties>
<log4j2.version>2.17.0</log4j2.version>
However, this is a specific solution for Log4j2, so I suggest you modify the title putting "Log4j2".

Question - ElasticSearch Baeldung Sample (Maven Dependencies)

I am trying to follow the example at https://www.baeldung.com/elasticsearch-java
But I am afraid there might be missing dependencies, as already in the first lines of code, my IDE is not being able to find the import for ClientConfiguration and RestClients, only for RestHighLevelClient.
I already added even more elasticsearch dependencies to my pom, but still same issue. My POM currently contains:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.6.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.6.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.6.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>7.6.2</version>
</dependency>
Could you please advise?
Thank you in advance.
This worked for me, seems to be part of the Spring data elastic search.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>4.2.5</version>
</dependency>
I already figured it out, but found useful to post it here, just in case. Indeed the article doesn't make clear there are other springframwork required dependencies, but you can find them in the very end, as it has a Github link, where you can see those classes come from:
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
Pom file direct link:
https://github.com/eugenp/tutorials/blob/master/persistence-modules/spring-data-elasticsearch/pom.xml

Atlassian JIRA Java REST API Fugue problem

I want to fetch data from a JIRA server using a simple Java program.
I got this in my POM, after trying a lot of different solutions found here and there.
<repositories>
<repository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/maven/repository/public</url>
</repository>
<repository>
<id>atlassian-public</id>
<url>https://mvnrepository.cpm/artifact/com.atlassian.fugue/fugue</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>io.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>4.7.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
My project builds, but when I run it I get the problem description below. I believe the simple logger is a warning, but what should I have done for io.atlassian.fugue to be found during runtime?
best rgds,
Niklas
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: io/atlassian/fugue/Suppliers
at com.atlassian.httpclient.apache.httpcomponents.ApacheAsyncHttpClient.(ApacheAsyncHttpClient.java:80)
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClientFactory.doCreate(DefaultHttpClientFactory.java:61)
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClientFactory.create(DefaultHttpClientFactory.java:36)
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:65)
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:36)
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithAuthenticationHandler(AsynchronousJiraRestClientFactory.java:47)
at MyJiraClient.getJiraRestClient(MyJiraClient.java:44)
at MyJiraClient.(MyJiraClient.java:27)
at MyJiraClient.main(MyJiraClient.java:31)
Caused by: java.lang.ClassNotFoundException: io.atlassian.fugue.Suppliers
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 9 more
This probably is an issue with the jira-rest-java-client-core (JRJC) and io.atlassian.fugue versions not working together. JRJC needs fugue, but you need to use the right version of fugue together with a given version of JRJC.
I've also struggled with this, but I haven't found anywhere / any way to figure out which fugue version actually works well with the newest JRJC version other than trying (and failing). I followed an example at Baeldung, but the JRJC version used there was old (4.0.0) so I wanted to use something newer.
Through trial and error, I found that these versions work well together, but the JRJC version is not the newest one, though:
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>io.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>4.7.2</version>
</dependency>
Note also that there is (as shown in the Baeldung example) a fugue artifact with groupId com.atlassian.fugue (instead of io.atlassian.fugue).
Although it's quite straight forward to use the java jira client but strange that version compatibility is not available.
For all people who are using spring-cloud-starter-netflix-eureka-client dependency, i want to share my findings.
My microservice was compiling and spinning up well with following dependencies:
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>io.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>5.0.0</version>
</dependency>
But throwing following exception while trying to use java jira client:
java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
After digging I realised that it is trying to access older version of jsr311-api coming from the spring boot eureka client.
I excluded it
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
And now it's running well. Hope this will help someone :)
Fistly, the SLF4J: Failed to load class warning, I think is different to your main error, you can clean or fix the warning adding a SLF4J Bridge maven dependency:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.13.3</version>
</dependency>
And later you can analyze the other root problem.

NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V

What Google Maven dependency could fix this error:
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V
at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:487)
at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:127)
at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:124)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:94)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:54)
at com.google.cloud.storage.BlobReadChannel.read(BlobReadChannel.java:124)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
at java.io.InputStream.read(InputStream.java:101)
Code:
Blob blob = storage.get(blobId);
if(blob.exists()) {
return true;
}
Your Google guava version is either too old (< 20.0) or mismatched (multiple jars versions). Make sure you don't have several versions in your dependency tree.
Use
mvn dependency:tree | less
to look for the guava versions.
Please add following dependencies to your project's POM:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.8</version>
</dependency>
In my case, I happened to include both
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
and
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
</dependency>
As it turns out, I cannot use both of these libraries. Removing google-collections fixed the issue for me.
Try inserting a dependency containing a newer version of guava at the top of your dependencies in your pom.xml containing your project.
E.g.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.1.1-jre</version>
</dependency>
For anybody encountering anything like this, i had the following pom:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
</dependency>
And commenting out the maven-shade plugin fixed it for me...
I had the same issue in my Java/Kotlin application. When the app was ran via IntelliJ there were no issues. However, when the .Jar was ran the error message above was thrown.
I could not find a direct action item to take with the Guava issue defined by #Laurent Perez above so I did the following which resolved the issue with my .Jar file running:
Removed .Jar IntelliJ configurations and file from IntelliJ. Then re-added the .Jar following Step 3 from this deploy guide.
Other actions to try if the above does not work:
Rebuild project.
Invalidate IntelliJ cache and restart.
Restart computer.
It happens when you're missing guava library from your dependency. Add it using following in your pom.xml
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
Another reason could be there are multiple versions of google guava/collection library, you can't have both as mentioned by #sabbir in his comment, you ought to remove one of them.
Lastly it could be that some other dependency is dependent on the previous version of google guava/collections. Go to Dependency Hierarchy and search for google and see what all dependencies are dependent on the previous versions. In my case it was by version-maven-plugin, version 2.7
Here version-maven-plugin, version 2.7 uses google collections 1.0, and I require guava 24.0 Both can't work simuntaneously.
I excluded it in my pom.xml like this and then added a new dependency of guava
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<exclusions>
<exclusion>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
Resultant: Now google-collections is gone.

Maven deps do not find version fields in POM

I have a Maven project which, following a restart, has had a peculiar issue: it reports that there is no version field for one of the dependencies (apache-camel), even though the field is in fact populated. I have checked the pom.xml source, and confirmed that the field is in fact there and populated for all the dependencies. I am uncertain why m2e is saying otherwise. Is this a known issue, and if so, is there a specific fix for it?
The version of the m2e plugin is 1.5.1, and this is the parent POM for the project. Here is the dependencies section of POM file in question:
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>apache-camel</artifactId>
<type>pom</type>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<type>pom</type>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<type>pom</type>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-parent</artifactId>
<type>pom</type>
<version>3.0.0-M2</version>
</dependency>
</dependencies>
I had the same problem with m2e saying that the version field was not present.
In my case the version field was not the problem. Actually the problem was, that the dependency was defined twice.
Have you checked if the apache-camel or any other dependency (maybe also from a parent pom) is defined twice?

Categories