Running hello world halts with java.lang.ClassNotFoundException: compojure.core

346 views
Skip to first unread message

Maarten Engelen

unread,
Aug 3, 2010, 5:31:23 PM8/3/10
to Compojure
Hi,

I'm trying to get the getting started code running, but this fails on
my machine with a java.lang.ClassNotFoundException: compojure.core
(core.clj:2)

My code looks like this:

(ns hello-www.core)
(:use compojure.core
ring.adapter.jetty)
(:require [compojure.route :as route]))

(defroutes example
(GET "/" [] "<h1>Hello World Wide Web!</h1>")
(route/not-found "Page not found"))

(run-jetty example {:port 8080})

First, the getting started text is incorrect, because 'lein repl'
doesn't accept any parameters anymore. Below is my repl:

user=> (require 'toodle.core)
java.lang.ClassNotFoundException: compojure.core (core.clj:2)
user=>

Also running it from the command line gives me a stack trace with the
same exception.

Any idea what's going on here? BTW, I tried combinations of clojure
1.1.0 and 1.2.0-beta1, as well as compojure 0.4.0 and 0.4.1

/Maarten

Nicolas Buduroi

unread,
Aug 3, 2010, 6:03:24 PM8/3/10
to Compojure
This is probably an issue with Leiningen 1.2, I've just tried it with
1.1 and everything work as advertised. Personally I had lots of
problems with Leiningen 1.2 under Cygwin and finally returned to the
previous release. I think we better wait for 1.2.1!

Maarten Engelen

unread,
Aug 4, 2010, 12:35:21 PM8/4/10
to Compojure
Well, even with leiningen 1.1 I get the same exceptions.

maarten$ lein repl src/hello-www/core.clj
Warning: the repl task currently doesn't honor some project.clj
options due to I/O stream issues. Future versions will address
this, but for now you will get more consistent behaviour from repls
launched by either the lein-swank plugin or the lein-nailgun plugin.

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.ClassNotFoundException: compojure.core (core.clj:
2)

So leiningen doesn't seem to be the problem. I checked the libs
directory and all the necessary libraries are there including
compojure-0.4.0.jar. unjarring this only gives me .clj files and no
compiled class files. Is this going to work?

maarten$ jar xvf lib/compojure-0.4.0.jar
inflated: META-INF/MANIFEST.MF
inflated: meta-inf/maven/compojure/compojure/pom.xml
inflated: meta-inf/maven/compojure/compojure/pom.properties
inflated: compojure/route.clj
inflated: compojure/response.clj
inflated: compojure/core.clj
inflated: project.clj

James Reeves

unread,
Aug 4, 2010, 2:05:55 PM8/4/10
to comp...@googlegroups.com
On 4 August 2010 17:35, Maarten Engelen <maarten...@gmail.com> wrote:
> Well, even with leiningen 1.1 I get the same exceptions.

Which platform/OS are you currently using?

Also, be aware that as Clojure is packaged as a library, and Compojure
currently depends on Clojure 1.1.0, you may get into trouble if you're
using Clojure 1.2.0-RC1

> So leiningen doesn't seem to be the problem. I checked the libs
> directory and all the necessary libraries are there including
> compojure-0.4.0.jar. unjarring this only gives me .clj files and no
> compiled class files. Is this going to work?

It should do, yes. The majority of Clojure jars are like this.

You could try a "lein clean" and then a "lein deps". Perhaps there's
something wrong with your lib directory?

Another option is to try starting it manually:

java -cp 'lib/*.jar' clojure.main src/hello-www/core.clj

You might also want to check your Java version as well.

- James

Maarten Engelen

unread,
Aug 4, 2010, 2:26:31 PM8/4/10
to Compojure
On 4 aug, 20:05, James Reeves <jree...@weavejester.com> wrote:
> On 4 August 2010 17:35, Maarten Engelen <maarten.enge...@gmail.com> wrote:
>
> > Well, even with leiningen 1.1 I get the same exceptions.
>
> Which platform/OS are you currently using?

I'm running Mac OS X 10.5.8 with Java 1.6.0_20 64 bit.

> Also, be aware that as Clojure is packaged as a library, and Compojure
> currently depends on Clojure 1.1.0, you may get into trouble if you're
> using Clojure 1.2.0-RC1

I've used Clojure 1.1.0 as well as 1.2.0-RC1. Both give me the same
problem.

>
> > So leiningen doesn't seem to be the problem. I checked the libs
> > directory and all the necessary libraries are there including
> > compojure-0.4.0.jar. unjarring this only gives me .clj files and no
> > compiled class files. Is this going to work?
>
> It should do, yes. The majority of Clojure jars are like this.
>
> You could try a "lein clean" and then a "lein deps". Perhaps there's
> something wrong with your lib directory?
>
> Another option is to try starting it manually:
>
> java -cp 'lib/*.jar' clojure.main src/hello-www/core.clj

I tried this and I still get the same error, which is exactly what
makes is odd.

maarten$ java -cp "lib/*" clojure.main src/hello-www/core.clj
Exception in thread "main" java.lang.ClassNotFoundException:
compojure.core (core.clj:2)

Explicitly naming clojure and compojure on the classpath ends up with
the same error:

java -cp lib/clojure-1.1.0.jar:lib/compojure-0.4.0.jar clojure.main
src/hello-www/core.clj
Exception in thread "main" java.lang.ClassNotFoundException:
compojure.core (core.clj:2)

The contents of the lib directory is also complete:

clojure-1.1.0.jar
clojure-contrib-1.1.0.jar
clout-0.2.0.jar
commons-codec-1.4.jar
commons-fileupload-1.2.1.jar
commons-io-1.4.jar
compojure-0.4.0.jar
jetty-6.1.14.jar
jetty-util-6.1.14.jar
ring-core-0.2.3.jar
ring-jetty-adapter-0.2.3.jar
ring-servlet-0.2.3.jar
servlet-api-2.5-6.1.14.jar
servlet-api-2.5.jar

And this is after I ran lein clean/lein deps.

/Maarten

Eduard Bondarenko

unread,
Aug 4, 2010, 2:47:28 PM8/4/10
to comp...@googlegroups.com
according to http://java.ittoolbox.com/groups/technical-functional/javaee-l/how-to-resolve-the-errorjavalangreflectinvocationtargetexception-1710507

Normally "java.lang.reflect.InvocationTargetException" occurs when
java compiler finds 2 different classes with same name in 2 different
packages. when u r importing both classes at a time and when you r
trying to create object of that class it throws
"java.lang.reflect.InvocationTargetException" exception .

Can you check your classpath? (echo $CLASSPATH)
and what java does mean? (> which java)

> --
> You received this message because you are subscribed to the Google Groups "Compojure" group.
> To post to this group, send email to comp...@googlegroups.com.
> To unsubscribe from this group, send email to compojure+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/compojure?hl=en.
>
>

Nicolas Buduroi

unread,
Aug 4, 2010, 3:05:54 PM8/4/10
to Compojure
That issue you're having is quite weird for sure! Change your code to
simply load clojure.contrib.classpath and print out (classpath-
jarfiles), maybe this will help us spot the source of the problem.

Maarten Engelen

unread,
Aug 4, 2010, 3:30:17 PM8/4/10
to Compojure
Eduard, Nicolas,

I checked the classpath from the repl:

java -cp "lib/*" clojure.main


(#<File lib/clojure-1.1.0.jar>
#<File lib/clojure-contrib-1.1.0.jar>
#<File lib/clout-0.2.0.jar>
#<File lib/commons-codec-1.4.jar>
#<File lib/commons-fileupload-1.2.1.jar>
#<File lib/commons-io-1.4.jar>
#<File lib/compojure-0.4.0.jar>
#<File lib/jetty-6.1.14.jar>
#<File lib/jetty-util-6.1.14.jar>
#<File lib/ring-core-0.2.3.jar>
#<File lib/ring-jetty-adapter-0.2.3.jar>
#<File lib/ring-servlet-0.2.3.jar>
#<File lib/servlet-api-2.5-6.1.14.jar>
#<File lib/servlet-api-2.5.jar>)

Doesn't look so weird to me.

I get the feeling I'm screwing up something rather basic or my java
environment has some serious problems...

Below the full strack trace when running the compojure project:

maarten$ java -cp "lib/*" clojure.main src/hello-www/core.clj
Exception in thread "main" java.lang.ClassNotFoundException:
compojure.core (core.clj:2)
at clojure.lang.Compiler.analyze(Compiler.java:4420)
at clojure.lang.Compiler.analyze(Compiler.java:4366)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2832)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:4594)
at clojure.lang.Compiler.analyze(Compiler.java:4405)
at clojure.lang.Compiler.analyze(Compiler.java:4366)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:3942)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:3777)
at clojure.lang.Compiler$FnMethod.access$1100(Compiler.java:3654)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3024)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:4590)
at clojure.lang.Compiler.analyze(Compiler.java:4405)
at clojure.lang.Compiler.eval(Compiler.java:4640)
at clojure.lang.Compiler.load(Compiler.java:4972)
at clojure.lang.Compiler.loadFile(Compiler.java:4939)
at clojure.main$load_script__7405.invoke(main.clj:213)
at clojure.main$script_opt__7442.invoke(main.clj:265)
at clojure.main$main__7466.doInvoke(main.clj:346)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.lang.Var.invoke(Var.java:359)
at clojure.lang.AFn.applyToHelper(AFn.java:173)
at clojure.lang.Var.applyTo(Var.java:476)
at clojure.main.main(main.java:37)
Caused by: java.lang.ClassNotFoundException: compojure.core
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 clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:
55)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.classForName(RT.java:1504)
at clojure.lang.Compiler.resolveIn(Compiler.java:4780)
at clojure.lang.Compiler.resolve(Compiler.java:4743)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:4720)
at clojure.lang.Compiler.analyze(Compiler.java:4387)
... 22 more


/Maarten

Eduard Bondarenko

unread,
Aug 4, 2010, 3:48:32 PM8/4/10
to comp...@googlegroups.com
Did you look into /Library/Java/Extensions ?
MacOSx adds that to classpath

Maarten Engelen

unread,
Aug 4, 2010, 4:08:54 PM8/4/10
to Compojure
/Library/Java/Extensions is completely empty in my case. The classpath
looks clean, my last message shows the content of the classpath.

/Maarten

James Reeves

unread,
Aug 4, 2010, 5:05:14 PM8/4/10
to comp...@googlegroups.com
Is it just Compojure, or are there other libraries that cause this same error?

- James

Maarten Engelen

unread,
Aug 5, 2010, 4:23:57 AM8/5/10
to Compojure
I should have thought of that before. I tried the following code:

(ns hello-www.core)
(:use ring.adapter.jetty)
(:require [compojure.route :as route]))

and now it cannot find the ring.adapter.jetty class

It looks like a more general problem is the cause, but I'm not sure
this list is the best place to ask about it.

/Maarten

On 4 aug, 23:05, James Reeves <jree...@weavejester.com> wrote:
> Is it just Compojure, or are there other libraries that cause this same error?
>
> - James
>

Maarten Engelen

unread,
Aug 5, 2010, 4:38:40 AM8/5/10
to Compojure
Ok, I got it to work. I'm still not sure what the problem was, but I
followed i slightly different procedure.

I started a new hello-www project and copy pasted the code like I did
before, but now I didn't use Textmate as my editor, but vi. And tada,
it works. My guess is something went wrong with the encoding of the
characters when copy-pasting from the browser screen to Textmate.

Thank you all for your help and if someone can enlighten me on why
this suddenly works, I would be happy to hear it. :)

/Maarten
Reply all
Reply to author
Forward
0 new messages