11 Feb 2009, 18:50
Generic-user-small

Clay Alberty (1 post)

I’m trying to get the “reader.tasklist” example in the book (b6.0, p89) to compile. I don’t have much java background, but I’ve tried using the repl.bat file as well as a variety of classpath settings from the java command-line. Each time I try to load the file from the repl, I get the following error:

user=> (load “reader/tasklist”) java.lang.ClassNotFoundException: reader.tasklist (tasklist.clj:14)

user=> (compile ‘reader.tasklist) java.io.IOException: The system cannot find the path specified (tasklist.clj:1)

I know it’s not my source code, because I installed NetBeans and got that to compile it fine, but I prefer to work in Emacs with Slime/Swank and I can’t get it to compile from the command line. The class is defined within the (ns) declaration at the top of the file, and it appears to have found the file in the directory tree with load (but maybe not with compile?), so…any suggestions?

16 Feb 2009, 08:19
Stu-small_pragsmall

Stuart Halloway (76 posts)

Hi Clay,

This is probably caused by not having a classes directory for the compiler to compile into. I have update the git repos to create the directory, so you should be able to update the sample code or just add the directory by hand.

Cheers, Stu

17 Feb 2009, 11:25
Generic-user-small

Bruce Gunderson (2 posts)

I’m having the same problem as Clay. I have a directory to compile into. The compiler produces a .class file in spite of the error message, but the file won’t execute. I’m working with examples.taaklist which was not prebuilt in the code download from the Pragmatic site an hour ago.

Here’s what javap and java have to say.

Any hints?

Bruce

Javap output for the classfile:

E:\Data\Clojure\ProgInClojure\code\classes>javap examples.tasklist public class examples.tasklist extends org.xml.sax.helpers.DefaultHandler{ public final java.lang.Object state; public static {}; public examples.tasklist(); public void warning(org.xml.sax.SAXParseException); public org.xml.sax.InputSource resolveEntity(java.lang.String, java.lang.Str ing); public void notationDecl(java.lang.String, java.lang.String, java.lang.Strin g); public void setDocumentLocator(org.xml.sax.Locator); public java.lang.String toString(); public void endDocument(); public void unparsedEntityDecl(java.lang.String, java.lang.String, java.lang .String, java.lang.String); public void fatalError(org.xml.sax.SAXParseException); public void startPrefixMapping(java.lang.String, java.lang.String); public void processingInstruction(java.lang.String, java.lang.String); public void skippedEntity(java.lang.String); public boolean equals(java.lang.Object); public void error(org.xml.sax.SAXParseException); public void startDocument(); public void characters(char[], int, int); public void ignorableWhitespace(char[], int, int); public void endElement(java.lang.String, java.lang.String, java.lang.String) ; public void endPrefixMapping(java.lang.String); public int hashCode(); public java.lang.Object clone(); public void startElement(java.lang.String, java.lang.String, java.lang.Strin g, org.xml.sax.Attributes); public static void main(java.lang.String[]); }

Output from attempted execution:

E:\Data\Clojure\ProgInClojure\code>java -cp classes;lib/clojure.jar;lib/clojure- contrib.jar examples.tasklist snippets\example-build.xml Exception in thread “main” java.lang.ExceptionInInitializerError Caused by: java.io.FileNotFoundException: Could not locate examples/tasklist__in it.class or examples/tasklist.clj on classpath: at clojure.lang.RT.load(RT.java:409) at clojure.lang.RT.load(RT.java:374) at clojure.core$load__4997$fn__4999.invoke(core.clj:3636) at clojure.core$load__4997.doInvoke(core.clj:3635) at clojure.lang.RestFn.invoke(RestFn.java:413) at clojure.lang.Var.invoke(Var.java:340) at examples.tasklist.(Unknown Source) Could not find the main class: examples.tasklist. Program will exit.

18 Feb 2009, 13:16
Generic-user-small

Bruce Gunderson (2 posts)

I had a mistake in my classpath. Now that it is corrected, the example works as described.

Sorry about that.

Bruce

28 Sep 2009, 18:47
Klang_pragsmall

Karsten Lang (1 post)

When working in the REPL with namespaces that has the :gen-class form, I have found that you get the above exception if compile-path isn’t in classpath.

Fair enough.

What took a bit longer to figure out was; you get the same exception, when trying to create a new object of the type the namespace you are currently developing in the REPL is defining.

An example and a longer explanation:

This situation occurs starting on page 77 of the book (paper), where we start by defining the ns reader.tasklist .. This returns nil in the REPL, as it is supposed to.

Fast forward to page 78 and defind the task-list, this will fail with a ClassNotFoundException if compile-path does NOT already contain a reader/tasklist.class from a previous compile. Delete it, refresh your REPL and you get the Exception.

I solved this by executing (compile ‘reader.tasklist) before defining task-list. In reality, compile just has to be called before creating a new object of the type the namespace defines. In this case it is (new examples.tasklist) that causes the ClassNotFoundException.

. .

10 Dec 2009, 00:59
1_pragsmall

Devender Gollapally (2 posts)

On a side note if you are on JDK 1.6 you can simply do ‘java -cp lib/*:classes reader.tasklist devdb.xml’ instead of mentioning each and every jar file. ‘*’ will pick up all jars in a directory.

-D

  You must be logged in to comment