0

I've compiled and I am now trying to run this program from the terminal in OSX and Fendora using the following command from within the ie directory:

java ie.moguntia.webcrawler.Psucker http://www.wikipedia.org test

However I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: ie/moguntia/webcrawler/Psucker
Caused by: java.lang.ClassNotFoundException: ie.moguntia.webcrawler.Psucker
    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)

I haven't ran applications that used packages from the command line before so I am therefore unable to figure out the error.

I have attempted to set the classpath using export CLASSPATH=. so that the current directory would be added to the classpath.

The directory structure is as follows:

ie/moguntia/webcrawler/

2
  • does the CWD has the required jar? Commented Mar 12, 2012 at 12:30
  • There are no require jar files. I should note that this runs fine on Windows. Commented Mar 12, 2012 at 12:46

2 Answers 2

2

Depending on where your compiled classes are located, you need to include this location in the java command, e.g. if they are in the classes directory:

java -cp classes ie.moguntia.webcrawler.PSucker http://www.wikipedia.org test

or if they are in the current directory:

java -cp . ie.moguntia.webcrawler.PSucker http://www.wikipedia.org test

or just

java ie.moguntia.webcrawler.PSucker http://www.wikipedia.org test

Here's how I was able to run this (unzip, cd to directory, compile, find classes, run):

(13:55:52) ~/Desktop/temp → ll
total 32
-rw-r--r--@ 1 Nils.Winkler  staff    14K 12 Mär 13:41 multiweb.zip

(13:56:01) ~/Desktop/temp → unzip multiweb.zip -d multiweb
Archive:  multiweb.zip
   creating: multiweb/CVS/
   creating: multiweb/ie/
   creating: multiweb/ie/CVS/
   creating: multiweb/ie/moguntia/
   creating: multiweb/ie/moguntia/CVS/
   creating: multiweb/ie/moguntia/threads/
   creating: multiweb/ie/moguntia/threads/CVS/
  inflating: multiweb/ie/moguntia/threads/ControllableThread.java  
  inflating: multiweb/ie/moguntia/threads/MessageReceiver.java  
  inflating: multiweb/ie/moguntia/threads/ObjectQueue.java  
  inflating: multiweb/ie/moguntia/threads/Queue.java  
  inflating: multiweb/ie/moguntia/threads/ThreadController.java  
   creating: multiweb/ie/moguntia/webcrawler/
   creating: multiweb/ie/moguntia/webcrawler/CVS/
  inflating: multiweb/ie/moguntia/webcrawler/PSucker.java  
  inflating: multiweb/ie/moguntia/webcrawler/PSuckerThread.java  
  inflating: multiweb/ie/moguntia/webcrawler/SaveURL.java  
  inflating: multiweb/ie/moguntia/webcrawler/URLQueue.java  
  inflating: multiweb/ie/moguntia/webcrawler/WSDLCrawler.java  
  inflating: multiweb/ie/moguntia/webcrawler/WSDLCrawlerThread.java 

(13:56:08) ~/Desktop/temp → cd multiweb

(13:56:57) ~/Desktop/temp/multiweb → javac ie/moguntia/webcrawler/*.java
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

(13:57:11) ~/Desktop/temp/multiweb → find . -name *.class
./ie/moguntia/threads/ControllableThread.class
./ie/moguntia/threads/MessageReceiver.class
./ie/moguntia/threads/Queue.class
./ie/moguntia/threads/ThreadController.class
./ie/moguntia/webcrawler/PSucker.class
./ie/moguntia/webcrawler/PSuckerThread.class
./ie/moguntia/webcrawler/SaveURL.class
./ie/moguntia/webcrawler/URLQueue.class
./ie/moguntia/webcrawler/WSDLCrawler.class
./ie/moguntia/webcrawler/WSDLCrawlerThread.class

(13:57:18) ~/Desktop/temp/multiweb → java ie.moguntia.webcrawler.PSucker http://www.wikipedia.org test
[0] http://www.wikipedia.org
Sign up to request clarification or add additional context in comments.

7 Comments

I've added the directory structure to the question.
Check the classname - it's PSucker with a capital S. I've changed my examples.
Sorry that was a typo, I've been running PSucker on my terminal.
Can you make sure that the class files are actually in the ie/moguntia/webcrawler directory? I unzipped the downloaded package into the multiweb folder, and I can run the command java ie.moguntia.webcrawler.PSucker http://www.wikipedia.org test from there without problems. I didn't have to provide any classpath when running from the same directory.
What's the output of find . -name *.class?
|
1

It should work if you run it from outside the ie directory.

Note that relying on the CLASSPATH environment variable is generally not recommended; instead explicitly put the classpath on hte command line using the -cp switch

2 Comments

I've tried running it from the directory above ie to no avail.
@Ash: well, it's never going to wrok from within, that's for sure. But if fixing that does not help, it might be a matter of file access rights.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.