System properties:
Java 1.6
Mac OSX version 10
Ant 1.8
Scenario: I am working on my final year project which is to create a website which uses Lucene to search my website and my database. I am working through lucene demos here
http://lucene.apache.org/java/2_3_2/demo.html
which talks about classpath
http://lucene.apache.org/java/2_3_2/demo3.html and a web example
I have created a .bash_profile file in my home directory /Users/philhunter/ which sets my classpaths:
CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/lucene-core-3.0.3.jar
CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/lucene-demo-3.0.3.jar
CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/src/demo/org/apache/lucene/demo
When i try and run the commands it asks on the command line i am getting ClassDefNotFoundError:
Exception in thread "main" java.lang.NoClassDefFoundError: /Users/philhunter/Desktop/COM562_Project/lucene-3/0/3/src/demo/org/apache/lucene/demo/IndexHTML
Caused by: java.lang.ClassNotFoundException: .Users.philhunter.Desktop.COM562_Project.lucene-3.0.3.src.demo.org.apache.lucene.demo.IndexHTML
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
The command line command is:
java /Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/src/demo/org/apache/lucene/demo/IndexHTML -create -index /Applications/MAMP/htdocs/
which should index my website files. That indexHTML file is a java file in that last classpath directory above. Anyone know why I am getting theat error!?
I think the path you're passing is the problem. Try adding the following to your bash script
cd /Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/src/demo/
java org.apache.lucene.demo.IndexHTML -create -index /Applications/MAMP/htdocs/
The problem is that when you run
java /Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/src/demo/org/apache/lucene/demo/IndexHTML
you are telling java run the class in the package Users.philhunter.Desktop.COM562_Project.lucene-3.0.3.src.demo.org.apache.lucene.demo.
Related
I am having trouble on setting up classpath on Mac. The following is the code I have attempted,
First I exported the jars using terminal
abc-MacBook-Pro:~ abc$ export
CLASSPATH=$CLASSPATH:/Users/abc/Desktop/IR/luceneJar/demo/lucene-demo-4.0.0.jar: export
CLASSPATH=$CLASSPATH:/Users/abc/Desktop/IR/luceneJar/core/lucene-core-4.0.0.jar: export
CLASSPATH=$CLASSPATH:/Users/abc/Desktop/IR/luceneJar/queryparser/lucene-queryparser-4.0.0.jar: export
CLASSPATH=$CLASSPATH:/Users/abc/Desktop/IR/luceneJar/analysis/common/lucene-analyzers-common-4.0.0.jar
Then when I echoed the classpath, following is the result
abc-MacBook-Pro:~ abc$ echo $CLASSPATH
/Users/abc/Desktop/IR/lucene-4.0.0 2/core/lucene-core 4.0.0.jar:
/Users/abc/Desktop/IR/lucene-4.0.0 2/demo/lucene-demo-4.0.0.jar:
/Users/abc/Desktop/IR/luceneJar/analysis/common/lucene-analyzers-common-4.0.0.jar
The error I am having is following when I tried to function the index file
abc-MacBook-Pro:~ abc$ java org.apache.lucene.demo.IndexFiles -docs
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/demo/IndexFiles
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.demo.IndexFiles
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Please let me know about the above error, thank you in advance. I am quite new with Lucene Java.
This is common Java classpath problem, nothing related to lucene (or mac) here.
Try this
1) Create lib folder and move all your lucene jars to lib
- lets say your project has two folders now lib and src, lib has all jars and src has yourJavaFile.java
2) Run below commands for compilation and execution from your src
- javac -cp ".:../lib/*" yourJavaFile.java
- java -cp ".:../lib/*" yourJavaFile
I usually use Weka from command line on Linux systems to perform feature selection on attributes as:
java -cp PATH_TO_WEKA_JAR weka.attributeSelection.CfsSubsetEval ... (other parameters)
I'm trying to run the same code on Mac OS but I have this error:
Exception in thread "main" java.lang.NoClassDefFoundError: weka.attributeSelection.CfsSubsetEval
Caused by: java.lang.ClassNotFoundException: weka.attributeSelection.CfsSubsetEval
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
How can I run the same command on Mac OS? Shouldn't be the same as it's a UNIX based OS?
I also tried to include the path within " " but there is no difference. What's is wrong?
Try this command:
jar tf PATH_TO_WEKA_JAR | grep weka.attributeSelection.CfsSubsetEval
In the output you should see a line with weka.attributeSelection.CfsSubsetEval.class.
If you don't see such line, then the jar file doesn't contain that class,
and the command cannot work.
In that case, try to run this:
jar tf PATH_TO_WEKA_JAR | less
to just see what is in the jar file.
One way or another, this is a simple class path issue:
the class weka.attributeSelection.CfsSubsetEval is simply not on your classpath.
You need to find the correct path to the jar,
possible to other dependencies as well,
and construct the correct parameter to use in:
java -cp CORRECT_CLASSPATH weka.attributeSelection.CfsSubsetEval # ... your other params
I guess there is something wrong with the Weka jar file. It tells you it can't find a particular class in the file.
Mac OS has evolved away from Unix quite a bit, which may make it necessary to use a differend JAR file.
This may help you: Weka Site download
I was following this tutorial to install JacORB Tutorial. In the last step, when I want to compile it, I got this error
Buildfile: /Users/adm/Downloads/jacorb/build.xml
base-init:
init-properties:
init-path:
init-javac-common:
init-javac-jdk:
init-javac-j2me:
init:
src-check:
BUILD FAILED
/Users/adm/Downloads/jacorb/build.xml:21: Unable to find src files. Is this a binary distribution?
But if I try ant in a demo file it builde successfully. I don't have to do the last step in the tutorial ? The second question is how to excute the build file ? after I builded the hello demo, I tried "jaco build" but I got a java exception
jaco build
Exception in thread "main" java.lang.NoClassDefFoundError: build
Caused by: java.lang.ClassNotFoundException: build
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
You likely have the binary distribution of JacORB.
Download the source distribution of JacORB instead. On the JacORB Download page, click the link for Full source code.
Or see https://github.com/JacORB/JacORB/ for the official source code.
I would recommend asking questions about JacORB on the jacorb-developer list (http://www.jacorb.org/contact.html)
I set up all my environment variable correctly but I'm getting a weird error, there is no match on google for the class name (which is just giberish)
So I added the 2 required environment variable :
JAVA_HOME C:\programs\Java\jdk1.6.0_41
M2_HOME C:\dev\apache-maven-3.0.4
And added this at the end of the variable PATH
;%JAVA_HOME%\bin;%M2_HOME%\bin
And when running mvn --version I get :
Exception in thread "main" java.lang.NoClassDefFoundError: ûXX
Caused by: java.lang.ClassNotFoundException: ûXX
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: ÔÇôXX. Program will exit.
The weird thing is that I get exactly the same thing on 2 totally different computers.
I tried with old file that I already had and freshly downloaded files.
I don't get it.
This works on my PC with Win7 64x OS:
JAVA_HOME c:\Program Files (x86)\Java\jdk1.6.0_21
J2_HOME c:\Program Files (x86)\Java\jdk1.6.0_21\bin
M2_HOME c:\Program Files (x86)\apache-maven-3.1.0
PATH ...;%M2_HOME%\bin;%J2_HOME%
Sometimes, when we want get PATH without spaces, we can use this trick:
'Progra~1' instead of 'Program Files'
'Progra~2' instead of 'Program Files (x86)'
and etc
This is old DOS filenames style: 8+3 - where 8 chars for name and 3 for extension (if it present)
This works on old Win machines
when passing maven path try to come in to maven package and get path, I had a maven package inside of maven package,so my path is C:\apache-maven-3.6.0\apache-maven-3.6.0. it is work on my computer.
I'm trying to to run my freshly installed apache solr on my server (CENTOS 5.2 x86_64) and I get the followoing error messages:
Exception in thread "main" java.lang.NoClassDefFoundError: start/jar
Caused by: java.lang.ClassNotFoundException: start.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: start.jar. Program will exit.
This is the commend I ran: java start.jar
As far as I'm aware everything is installed correctly.
Any ideas?
Thanks
C
Run it with java -jar, not java:
java -jar start.jar
The java command is used for running .class files, while the java -jar command actually executes the code in the jar properly, using the manifest file to interpret the jar's contents.