Twitter4j JSONObject Doesn't exist - java

I have following maven dependency
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.1.2</version>
</dependency>
But when i do this
import twitter4j.JSONObject;
I get error that object doesn't exist.
This is an existing code which was working in prod at sometime. Recently pulled latest branch. The code was built for Java8. I Am using Java19. I am on windows 11
Update: Installed/configured Java8. Same issue.

Related

How do we create an IndexRequest in Java for ElasticSearch 7.4.2 Java High Level REST Client?

I am trying to insert data into ElasticSearch (version 7.4.2) hosted on bonsai.io cloud. When I try to create an IndexRequest & IndexResponse in my client code in Java (Java High Level REST client), there is no import available for both IndexRequest & IndexResponse.
My pom.xml has the following dependencies:
<dependencies>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
I even tried adding the below dependency to my pom.xml
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.4.2</version>
</dependency>
Can somebody help me solve this issue in 7.4.2 version?
Please check this GitHub repo which is using ES 7.3 with java high-level rest client. You can change the ES client version in pom.xml and ready to go, as these are just minor version change, there isn't really any change in IndexRequest and indexResponse APIs.
Please see this of com.indore.GalaxyApp#createIndex method, where IndexRequest is created.
You can change your elasticsearch details config.yml and read the README section on how to start the app.
Let me know if you need more information.
Error occurred as the maven build was unable to read the jar manifest for following 2 jar files.
1) .m2/repository/org/elasticsearch/elasticsearch/7.4.2/elasticsearch-7.4.2.jar
2) .m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/7.4.2/elasticsearch-rest-high-level-client-7.4.2.jar
Solved the error by deleting the .m2 directory locally. Running the pom.xml after this as a maven build fixed the error and the above 2 jars were installed correctly.

Error using MongoDB 3.4.2 with Java

I am facing this issue while using MongoDB 3.4.2 in Java Maven Project
The type com.mongodb.WriteConcern cannot be resolved. It is indirectly referenced from required .class files
here is the dependency added in pom.xml
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.4.2</version>
<scope>test</scope>
</dependency>
Is there is something I am missing?
WriteConcern.class file is missing in downloaded jar. download 2.12 it has and working fine.

Elasticsearch 5.0 and Elasticsearch-Spark connector - what is correct maven artefact

When writing application to run on Apache Spark 1.6 using Elasticsearch-Spark connector, documentation at (https://www.elastic.co/guide/en/elasticsearch/hadoop/5.0/install.html#_minimalistic_binaries) says to use maven artefact
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-spark_2.10</artifactId>
<version>5.0.0</version>
</dependency>
However maven fails with error message that specified artefact cannot be found. After searching through maven central I found however alternative versions:
For Spark 1.3+
<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch-spark-13_2.10</artifactId>
    <version>5.0.0</version>
</dependency>
For Spark 2.*
<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch-spark-20_2.10</artifactId>
    <version>5.0.0</version>
</dependency>
Ah, got the answer from ES folks. It is a bug in documentation, going to be fixed soon. https://github.com/elastic/elasticsearch-hadoop/issues/890#issuecomment-258511400

java.lang.ClassNotFoundException: com.amazonaws.ClientConfigurationFactory

I am using aws since last 6 months and I developed application that puts batch request to firehose. It was working fine till today but when I redeployed in my local system it is saying java.lang.ClassNotFoundException: com.amazonaws.ClientConfigurationFactory. I know what this error means. But my question is why I got this exception today? I am using following dependency in my project:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<!-- <version>1.10.72</version> --> // I used this version today only for testing purpose
<version>1.10.6</version>
</dependency>
<!-- <dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.10.71</version>
</dependency> -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.10.37</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-kinesis</artifactId>
<version>RELEASE</version>
</dependency>
And I searched ClientConfigurationFactory class but don't find anywhere (anywhere means in my dependency).
My question is where is this class located and why I got this error only today? Because I did not face this error in my initial development (6 months before). I have not changed any dependencies/code today. And I am not using this class in my project (I have doubt aws-sdk may have been using inside).
Note: I can not ask Do I missed any dependency? Because it was working fine before.
Please comment if you have any doubt. Thanks.
This is most likely because you have a mismatch of AWS SDK versions you are including. You are using a combination of SDK version 1.10.6, 1.10.71, 1.10.37 and RELEASE. You are asking for trouble mixing the versions like you are doing. Change all those to the same version and your problem will likely go away.

Jena NoClassDefFoundError with Maven

I have a Java Maven project that I developed a while ago and that doesn't work anymore. It uses a parent pom together with another Maven project in which I think the Jena version was changed and it also uses an external library that uses Jena. The Maven dependency is:
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>jena</artifactId>
<version>2.6.4</version>
</dependency>
When I execute my tests I get the following errors:
java.lang.NoClassDefFoundError: Could not initialize class
com.hp.hpl.jena.query.ARQ
java.lang.NoClassDefFoundError: org/apache/jena/iri/IRIFactory
at org.openjena.riot.system.PrefixMap.add(PrefixMap.java:54)
at com.hp.hpl.jena.sparql.util.MappingRegistry.addPrefixMapping(MappingRegistry.java:33)
at com.hp.hpl.jena.query.ARQ.init(ARQ.java:449) [...]
The errors are not thrown by my code directly but by the library I include. Can I prevent this by downgrading the Jena version in the parent pom or what can I do here?
P.S.: I now have a minimal code example that reproduces the error (java.lang.NoClassDefFoundError: org/apache/jena/iri/IRIFactory):
import org.junit.Test;
import com.hp.hpl.jena.query.ARQ;
public class DependencyTest
{
#Test
public void testARQ()
{
ARQ a = new ARQ();
}
}
And I guess it comes from this dependency:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.9.1-incubating-SNAPSHOT</version>
</dependency>
I know there is probably a factory instead of a constructor but I guess this still shows where the problem is.
P.S.: I noticed that I had the dependencies "jena", "arq" and "jena-arq":
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>arq</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.9.1-incubating-SNAPSHOT</version>
</dependency>
dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>jena</artifactId>
<version>2.6.4</version>
</dependency>
So I thought maybe I have too much overlapping dependencies and commented out "jena" and "arq". But I still get the error
java.lang.NoClassDefFoundError: Could not initialize class com.hp.hpl.jena.query.ARQ
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.<init> [...]
I also tried out forcing a non-snapshot-version 2.9.0-incubating, but then I still get the NoClassDefFoundError with and without using the "jena" and "arq"-dependencies.
P.P.S.:
I still get the same error even when I use the following dependencies:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.9.0-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>2.7.0-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-iri</artifactId>
<version>2.7.0-incubating</version>
</dependency>
You can search for the missing class using the Maven Central search application
http://search.maven.org/#search|ga|1|fc%3A%22com.hp.hpl.jena.query.ARQ%22
It demonstrates that the dependency you appear to be missing is:
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>arq</artifactId>
<version>2.6.0</version>
</dependency>
Doesn't appear to be a version 2.6.4, but you're probabily best advised to go for a more modern version (This project was recently donated to apache)
Instructions for using Apache Jena with Maven are here:
incubator.apache.org/jena/download/maven.html
Specifying ARQ 2.9.0 as a dependency in your project pom.xml will pull in the other Jena components that you need.
I finally resolved this error by excluding the "jena"-Dependency brought in as a transitive dependency from some library.

Categories