Solrj - cannot inherit from final class error due to HTTPSolrServer - java

I have been using Solr version 4.10.2. I added solrj version 4.10.2 by using maven (pom.xml)
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.10.2</version>
<scope>compile</scope>
</dependency>
These are maven dependencies that are installed:
solr-solrj-4.10.2.jar
httpclient-4.3.1.jar
httpcore-4.3.jar
httpmime-4.3.1.jar
wstx-asl-3.2.7.jar
wstx-asl-3.2.7.jar
noggit-0.5.jar
When I define solr http path, l get and exception:
Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:157)
at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:447)
at org.apache.solr.client.solrj.impl.HttpClientUtil.setFollowRedirects(HttpClientUtil.java:260)
at org.apache.solr.client.solrj.impl.HttpClientConfigurer.configure(HttpClientConfigurer.java:60)
at org.apache.solr.client.solrj.impl.HttpClientUtil.configureClient(HttpClientUtil.java:142)
at org.apache.solr.client.solrj.impl.HttpClientUtil.createClient(HttpClientUtil.java:118)
at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:168)
at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:141)
at addIndex.main(addIndex.java:10)
This is how I define solr path:
HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr"); or
HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr/#/collection1");
Is there another way to make a connection with java project? What is the reason that I get this exception?

If you're connecting to Solr (and using SolrJ as the client library), you're supposed to instantiate HttpSolrClient:
String urlString = "http://localhost:8983/solr/collection1";
SolrClient solr = new HttpSolrClient(urlString);
BTW: Anchors in URLs (such as #foo) is meant for clients only (such as browsers), and are not meant to be (and thus, isn't, usually) transmitted as part of the request.

Related

Apache NiFi Custom NAR NoClassDefFoundError During Startup

I am attempting to install a custom NAR controller service bundle in my NiFi installation but get this error during startup. It acts like it can't find the RecordReaderFactory class from the nifi-record-serialization-service-api even though it is included as a dependency:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-serialization-service-api</artifactId>
<version>1.9.0</version>
</dependency>
Here is the project:
https://github.com/adamfisher/nifi-zonefile-record-serialization-service
Running maven install builds the NAR successfully. It's just when I startup NiFi, it gives this error. I'm pretty sure this is a maven POM configuration issue. I just don't work with Java too much and hoping someone can shed some light on why it is not finding the dependent class it needs?
nifi-app.log:
2019-03-02 15:22:15,245 INFO [main] org.apache.nifi.web.server.JettyServer Loading WAR: D:\nifi\NIFI-1~2.0\.\work\nar\framework\nifi-framework-nar-1.9.0.nar-unpacked\NAR-INF\bundled-dependencies\nifi-web-error-1.9.0.war with context path set to /
2019-03-02 15:22:15,261 INFO [main] org.apache.nifi.web.server.JettyServer Running in HTTP mode; host headers not restricted
2019-03-02 15:22:16,386 ERROR [main] org.apache.nifi.NiFi Failure to launch NiFi due to java.lang.NoClassDefFoundError: org/apache/nifi/serialization/RecordReaderFactory
java.lang.NoClassDefFoundError: org/apache/nifi/serialization/RecordReaderFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.apache.nifi.nar.StandardExtensionDiscoveringManager.loadExtensions(StandardExtensionDiscoveringManager.java:152)
at org.apache.nifi.nar.StandardExtensionDiscoveringManager.discoverExtensions(StandardExtensionDiscoveringManager.java:127)
at org.apache.nifi.nar.StandardExtensionDiscoveringManager.discoverExtensions(StandardExtensionDiscoveringManager.java:113)
at org.apache.nifi.web.server.JettyServer.start(JettyServer.java:925)
at org.apache.nifi.NiFi.<init>(NiFi.java:158)
at org.apache.nifi.NiFi.<init>(NiFi.java:72)
at org.apache.nifi.NiFi.main(NiFi.java:297)
Caused by: java.lang.ClassNotFoundException: org.apache.nifi.serialization.RecordReaderFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 common frames omitted
2019-03-02 15:22:16,387 INFO [Thread-1] org.apache.nifi.NiFi Initiating shutdown of Jetty web server...
2019-03-02 15:22:16,387 INFO [Thread-1] org.apache.nifi.NiFi Jetty web server shutdown completed (nicely or otherwise).
The NAR dependencies are used at runtime to create a chain of parent class loaders. So in your example you have
nifi-zonefile-record-serialization-service-nar -> (depends on)
nifi-zonefile-record-serialization-service-api-nar -> (depends on)
nifi-standard-services-api-nar
In the running application when it instantiates the instance of your record reader from your service NAR, it then needs to load the interface that implements which comes from your service API NAR, which then needs to load the RecordReader interface which comes from the standard services API NAR.
I have spent a lot of time on this. Finally, i have a working solution for me. My custom processor is using RecordReader for incoming stream. However, either compile or package failed in maven process. I had to customize pom.xml as following:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-serialization-service-api</artifactId>
<version>${nifi.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-serialization-services-nar</artifactId>
<version>${nifi.version}</version>
<type>nar</type>
</dependency>
I ended up needing to include the API NAR file as well even though it doesn't appear to be used anywhere. It's just a generic template class called MyService.
I have the same issue as described here and I managed to solved it including the dependencies at the nar module(nifi-base-nar) pom.xml
The dependency that you need to include is the following:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-standard-services-api-nar</artifactId>
<version>${nifi.version}</version>
<type>nar</type>
</dependency>

NoClassDefFoundError org/apache/poi/ss/usermodel/Workbook

I am running a shell script which calls a java class to get some data from database and create an excel report with that data. I get the error Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook when the code hits the below line in my java class:
XSSFWorkbook workbook = new XSSFWorkbook ();
This is how I have defined the classpath:
CLASSPATH=${CLASSPATH}:<path-to-jars>/poi-2.5.1-final-20040804.jar
CLASSPATH=${CLASSPATH}:<path-to-jars>/poi-ooxml-3.11.jar
I verified that the jars have been downloaded(via gradle), so trying to understand what am I missing here. Can someone please help me with this?
Stacktrace:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.test.ExcelReportGenerator.writeExcel(ExcelReportGenerator.java:26)
at com.test.ReportRunner.createReport(ReportRunner.java:109)
at com.test.ReportRunner.main(ReportRunner.java:93)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 15 more
As per this Apache POI FAQ entry, mixing POI jars between different versions is not supported and will break in all sorts of ways, such as the one you've found. Don't do it!
You need to be using your POI jars all from the same release. I'd suggest the latest version, available here (currently 3.15)
You should probably also review the components and their dependencies page, to ensure you've got all the required jars for your use of Apache POI. Well, or use a dependency management tool like Maven or Gradle to handle that for you!
I have downloaded the latest Apache POI binaries v3.17 here and it has all the required jars to create xlsx file and open with out any fuss.
Required jars are shown in below screenshots (refer to selected jars) FYR.
For apache poi to work, you need compatible jars.
I used these jars
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>openxml4j</artifactId>
<version>1.0-beta</version>
</dependency>
Delete the poi jar from your maven repository and download or build the project again.
poi 2.5.1 had no such package (and consequently a class) included (you can verify by unpacking the jar files as they are essentially zip archives). See the source.
Update the poi dependency to release 3. This also has the added benefit of matching the ooxml version.

Netbeans, ClassNotFoundException

There is my following problem :
java.lang.ClassNotFoundException: javax.vecmath.Point3f
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:244)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
Caused: java.lang.NoClassDefFoundError: javax/vecmath/Point3f
I don't really understand why it can't find this class. I have the latest version of Java 1.7. Any ideas ?
Best regards.
If you are using Maven, try to add this dependency please :
<dependency>
<groupId>java3d</groupId>
<artifactId>vecmath</artifactId>
<version>1.3.1</version>
</dependency>
Otherwise, download the latest java3d library : https://java3d.java.net/binary-builds.html
After imported, update your imports in your Java class and it should be fine to compile.
Point3f is part of the Java3D API, which is a separate download. Read more here.
Cheers,

Illegal UTF8 string in constant pool in class file error in IntelliJ

Whenever I try to run a file (java main, cucumber feature, junit test) I get the following error in IntelliJ Idea:
Information:15/05/2015 14:57 - Compilation completed with 1 error and 0 warnings in 1s 134ms
Error:Internal error: (java.lang.ClassFormatError) Illegal UTF8 string in constant pool in class file org/jetbrains/jps/model/serialization/java/JpsJavaModelSerializerExtension$JavaProjectExtensionSerializer
java.lang.ClassFormatError: Illegal UTF8 string in constant pool in class file org/jetbrains/jps/model/serialization/java/JpsJavaModelSerializerExtension$JavaProjectExtensionSerializer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension.getProjectExtensionSerializers(JpsJavaModelSerializerExtension.java:80)
at org.jetbrains.jps.model.serialization.JpsProjectLoader.loadFromDirectory(JpsProjectLoader.java:118)
at org.jetbrains.jps.model.serialization.JpsProjectLoader.loadProject(JpsProjectLoader.java:98)
at org.jetbrains.jps.model.serialization.impl.JpsSerializationManagerImpl.loadModel(JpsSerializationManagerImpl.java:41)
at org.jetbrains.jps.cmdline.JpsModelLoaderImpl.loadModel(JpsModelLoaderImpl.java:45)
at org.jetbrains.jps.cmdline.BuildRunner.load(BuildRunner.java:78)
at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:265)
at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:124)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:242)
at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
I tried restarting the IDE, importing the project again but nothing worked. Did anyone experience this error before ?
I have managed to fix this by deleting .IntelliJIdea folder and reimporting the project.
Adding this answer for those who also experience this issue not only in IntelliJ but also with maven builds outside IntelliJ. Reinstalling the JDK was the only solution that worked for me.

Which jars are required for embedded Neo4j?

I'm looking for an updated answer to this question. Previously, a minimal Neo4j "Hello World" app required two jars. Now it apparently requires some other jars, but I don't know which ones.
If I include neo4j-kernel-2.1.2 and geronimo-jta_1.1_spec-1.1.1 as suggested in that other question, I get this error:
java.lang.ClassNotFoundException: org.neo4j.collection.primitive.PrimitiveLongIterator
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
If I add neo4j-primitive-collections-2.1.2, I then get an error with this root cause:
Caused by: java.lang.IllegalArgumentException: No schema index provider org.neo4j.kernel.api.index.SchemaIndexProvider found.
Answers on this question suggest I need neo4j-lucene-index. When I add that jar, I get this error:
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.store.Directory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
Finally, when I add lucene-core, I get this error:
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.document.Fieldable
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
What do I need to add to get past that?
I believe I've found the minimal set of dependencies for Neo4j 2.x. I was originally trying to use lucene-core-4.9.0, but the org.apache.lucene.document.Fieldable interface was removed from that library sometime after version 3.6.2. The minimal set of jars is thus:
neo4j-kernel (2.1.2)
neo4j-primitive-collections (2.1.2)
neo4j-lucene-index (2.1.2)
lucene-core (3.6.2)
jta (1.1)
These weigh in at about 4.5 MB, which is larger than I'd like, but I guess I can live with it. I've also been told that neo4j-lucene-index (which is what requires lucene-core) is not strictly required. Like jta, it's actually only one possible implementation of a required interface. But I don't know of any other implementation.
As the other answer correctly mention the most easy way is use a build tool featuring a dependency manager. Most widely these days used are Maven and Gradle. Both use Maven Central repository by default to pull dependencies and transitive dependencies.
Depending whether your embedded application uses cypher or not you should add the following dependencies your pom.xml:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-lucene-index</artifactId>
<version>2.1.2</version>
</dependency>
or (when cypher is used):
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-cypher</artifactId>
<version>2.1.2</version>
</dependency>
Both of them transitively include all necessary libraries.

Categories