I'm trying to use Lucene StandardTokenizer as in the code below:
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.util.Version;
public class App {
public static void main(String[] args) throws Exception {
// line 28 goes below
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
// the rest is irrelevant
}
}
It is throwing VerifyError:
Exception in thread "main" java.lang.VerifyError: class org.apache.lucene.analysis.standard.StandardTokenizer overrides final method setReader.(Ljava/io/Reader;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at lt.App.main(App.java:28)
Any ideas how to fix this? Thanks a lot.
Do you have 2 different versions of lucene in your classpath?
The method setReader(...) was added to StandardTokenizer in the 4.0.0-BETA version. But it was later removed from StandardTokenizer and made final in Tokenizer before the 4.0.0 release version. So I you may have the 4.0.0-BETA version of the lucene-analyzers-common jar in your classpath and the 4.0.0 release version of lucene-core jar.
LUCENE-4343 is probably the issues that changed this.
Related
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import java.io.IOException;
public class FeedIntoSolr{
public static void main(String[] args) throws IOException, SolrServerException {
HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr");
for(int i=0;i<1000;++i) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("cat", "book");
doc.addField("id", "book-" + i);
doc.addField("name", "The Legend of the Hobbit part " + i);
server.add(doc);
if(i%100==0)
server.commit(); // periodically flush
}
server.commit();
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase
at FeedIntoSolr.main(FeedIntoSolr.java:9)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpRequestBase
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)
... 1 more
You are missing httpclient's jar in your classpath.
Ensure you have this jar in your classpath and you should get rid of this error.
You need to add http client implementation
You can update your pom.xml with maven
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency>
Or download it at https://hc.apache.org/downloads.cgi and add it to the classpath in Eclipse with Project > Properties > Build Path
Thanks to all for responding..I got the answer of question asked by me.
1)first of all you need to add the jar files which is already available in solr folder(you will see when you unzipped it)
2)Jar Files in the folder solr-5.2.1->dist( add only solr-solrj-5.2.1.jar in classpath) and solr->dist->solrj-lib(add all jar in classpath)
3)you have to add two another file commons-logging-1.2.jar and slf4j-simple-1.7.12.jar
This is working for me..
After migration to Java 8, my tool throw the follwing exception if somebody try to run it on earlier Java environments.
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/myapp/MyTool: Unsupported major.minor version 52.0
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 sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Is there some way to not show this error, and show nice error message with proposition to upgrade Java.
As I understood I should create some small class like:
public class CheckerJavaVersion {
public static void main(String args[]) {
String sVersion = System.getProperty("java.version");
sVersion = sVersion.substring(0, 3);
Float f = Float.valueOf(sVersion);
if (f.floatValue() < (float) 1.8) {
System.out.println("Please upgrate your Java to 1.8 version");
System.exit(1);
}
}
}
and compile it via older compiler. I need some solution how to run this class firstly before the main method of MyToll class starts.
PS. Aplication is packed in jar.
The problem is that the error occurs when the class is loaded, so you'd either have to use a "starter app" which starts the actual application in a separate process or dynamically load the application after the Java version has been checked.
I didn't test it but what might work is something like this:
public static void main(String args[]) {
if( javaVersionOk ) {
Class.forName("actual.mainclass.name").getMethod("actual.main.method.name").invoke();
}
}
The idea is to access the class via its name and thus make the runtime load and initialize it at that time. I'm not sure, however, if you can delay class loading like that in all cases so you'd have to go on from there.
And btw, IIRC there already are applications/libraries that provide this kind of functionality, I just don't rember their names. So a search might be worth your while.
Edit: you might want to have a look at appstart if not for using it then for inspiration.
Another launcher would be Apache Commons Launcher.
Alternatives:
Alternatively you could just provide a launch script for each platform you want to support , call java -version and check the returned version before launching the application.
Another alternative would be to use JNLP/WebStart locally, which allows you to specify a minimum version and which AFAIK even provides for download/upgrade functionality.
I am using following jars-
commons-validator-1.4.0 ; commons.logging-1.2 ; commons.digester-1.8 ;commons.beanutils-1.8.3
commons.collections-3.2.1
but keeps on getting same error at line -
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Rule
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:423)
com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:216)
This is the code i am writing -
InputStream in = this.getClass().getResourceAsStream("validator-name-required.xml");
// Create an instance of ValidatorResources to initialize from an xml file.
ValidatorResources resources = new ValidatorResources(in);
Please help its been a day i am stuck into this error !! Thanks in advance
Finally i am able to do this. I have used the following jars -
commons-beanutils-1.8.3.jar
commons-collections-3.2.1.jar
commons-digester-1.8.jar
commons-logging-1.1.1.jar
commons-validator-1.4.0.jar
and this works :)
Its look like that "org.apache.commons.digester.Rule" class was not found, Version 2.1 of digester have Rule.class, download this version and try.
I saw this post but I wasn't clear on what the resolution was.
I'm trying to run a java program from command line utilizing an external library. Here is the total output of my session:
grifter#host:~/java$ cat ExtractTest.java
import java.io.IOException;
import org.apache.pdfbox.util.PDFTextStripper;
import org.apache.pdfbox.pdmodel.PDDocument;
import java.io.File;
public class ExtractTest {
public static void main(String[] args) throws IOException {
System.out.println("About to open PDF");
File fh = new File("/home/grifter/test.pdf");
PDDocument d = PDDocument.load(fh);
System.out.println("Here");
PDFTextStripper ts = new PDFTextStripper();
System.out.println(ts.getText(d));
}
}
grifter#host:~/java$ javac -cp .:/home/grifter/pdfbox-1.8.5/pdfbox/target/pdfbox-1.8.5.jar ExtractTest.java
grifter#host:~/java$ java -classpath .:/home/grifter/pdfbox-1.8.5/pdfbox/target/pdfbox-1.8.5.jar ExtractTest
About to open PDF
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.pdfbox.pdfparser.BaseParser.<clinit>(BaseParser.java:68)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1219)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1187)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1158)
at ExtractTest.main(ExtractTest.java:12)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
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)
... 5 more
Could someone please point me in the right direction?
Any help is appreciated.
pdf box uses dependencies, which also needs to be added to your class path. You can read about the dependecies here
The jar commons-logging and the dependencies is missing in your classpath.
You can download it here
I have some problems testing a program from a java programming book. I wrote the code in eclipse and succeded running it, but when I compile the .java file via the command line and then run it with java ConsoleEcho, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: ConsoleEcho (wrong na
me: einausgabe/ConsoleEcho)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
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:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
The code for my program is:
package einausgabe;
import java.io.IOException;
import static java.lang.System.*;
public class ConsoleEcho {
public static void main( String args[] ) throws IOException {
while( true ) {
int code = in.read();
out.write(code);
}
}
}
The commands I used are:
javac ConsoleEcho
java ConsoleEcho
I run this from the directory ..\Java\ProgrammierenMitJava2\src\einausgabe
I don't get any errors by compiling. Tried java einausgabe.ConsoleEcho and then I get this error message:
Error: Could not find or load main class einausgabe.ConsoleEcho
You need to include the package name in the command line, something like:
java einausgabe.ConsoleEcho
you appear to just have the class name in your command.
It seems that you forgot the package name
Use
java einausgabe.ConsoleEcho