Unable to build a simple project with clojure-ant-tasks

22 views
Skip to first unread message

Ivan Chernetsky

unread,
Aug 30, 2009, 10:15:30 AM8/30/09
to clo...@googlegroups.com
Hello!

I wrote build.xml with the following content:

<project name="edn-extractor" default="jar">
<property name="src.dir" location="src" />
<property name="classes.dir" location="classes" />
<property name="jar.name" value="edn-extractor.jar" />

<path id="project.classpath">
<pathelement location="${src.dir}" />
<pathelement location="${classes.dir}" />
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</path>

<target name="clean" description="Remove generated files.">
<delete dir="${classes.dir}" />
<delete file="${jar.name}" />
</target>

<target name="def-tasks">
<taskdef name="compile-clojure"
classname="com.ubermensch.ant.clojure.CompileTask"
classpath="lib/clojure.jar:lib/clojure-contrib.jar:lib/clojure-ant-tasks.jar"
/>
</target>

<target name="compile" depends="def-tasks">
<mkdir dir="${classes.dir}" />
<compile-clojure>
<classpath>
<path refid="project.classpath" />
</classpath>
</compile-clojure>
</target>

<target name="jar" depends="compile">
<jar jarfile="${jar.name}" basedir="${classes.dir}">
<fileset dir="${src.dir}">
<include name="**/*.clj" />
</fileset>
</jar>
</target>
</project>

And I have a simple directory structure:

# find .
./build.xml
./src
./src/edn
./src/edn/main.clj
./lib
./lib/clojure-contrib.jar
./lib/clojure.jar
./lib/clojure-ant-tasks.jar

Here is the content of main.clj:

(ns edn.main
(:gen-class))

(defn -main
[greetee]
(println (str "Hello " greetee "!")))

Then if I run ant, I get:

Buildfile: build.xml

def-tasks:

BUILD FAILED
java.lang.ExceptionInInitializerError
at clojure.lang.Namespace.<init>(Namespace.java:32)
at clojure.lang.Namespace.findOrCreate(Namespace.java:122)
at clojure.lang.Var.internPrivate(Var.java:94)
at com.ubermensch.ant.clojure.base_task.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:583)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:228)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
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 org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException:
Could not locate clojure/core__init.class or clojure/core.clj on
classpath:
at clojure.lang.RT.<clinit>(RT.java:295)
... 25 more
Caused by: java.io.FileNotFoundException: Could not locate
clojure/core__init.class or clojure/core.clj on classpath:
at clojure.lang.RT.load(RT.java:402)
at clojure.lang.RT.load(RT.java:371)
at clojure.lang.RT.doInit(RT.java:406)
at clojure.lang.RT.<clinit>(RT.java:292)
... 25 more

Total time: 0 seconds

Either of clojure/core.clj and clojure/core__init.class is on
classpath, I think. What am I doing wrong?

J. McConnell

unread,
Aug 30, 2009, 11:46:41 AM8/30/09
to clo...@googlegroups.com
On Sun, Aug 30, 2009 at 10:15 AM, Ivan Chernetsky <ivan.ch...@gmail.com> wrote:

Either of clojure/core.clj and clojure/core__init.class is on
classpath, I think. What am I doing wrong?

Hmmm ... This builds fine for me (with the inclusion of <namespace>edn.main</namespace> in the <compile-clojure /> element). I've uploaded what I have here so you can try it on your machine:

http://github.com/jmcconnell/test-clojure-ant-project/tree/master

What versions of Clojure and Clojure-Contrib are you using? The Ant task currently only supports Clojure 1.0, because I had to choose between supporting clojure.contrib.test and clojure.test and I thought there would be more interest in a 1.0-compatible version. I'd be happy to revisit that decision if there's interest.

Also, which version of Ant?

Regards,

- J.

Ivan Chernetsky

unread,
Aug 30, 2009, 1:02:18 PM8/30/09
to clo...@googlegroups.com
2009/8/30 J. McConnell <jdo...@gmail.com>:

> Hmmm ... This builds fine for me (with the inclusion of
> <namespace>edn.main</namespace> in the <compile-clojure /> element). I've
> uploaded what I have here so you can try it on your machine:

I have just pasted this too.

> http://github.com/jmcconnell/test-clojure-ant-project/tree/master

It seems to be identical.

> What versions of Clojure and Clojure-Contrib are you using?

The freshest ones.

> Also, which version of Ant?

ivan@inote edn-extract % ant -version
Apache Ant version 1.7.1 compiled on August 29 2009

Here is the debug output: http://pastebin.com/m6306a855

I have just tried "ant -lib lib" and everithing's ok.

ivan@inote edn-extract % java -cp lib/clojure.jar:edn-extractor.jar
edn.main "Big Brother"
Hello Big Brother!

I'm curious what may be the reason!

J. McConnell

unread,
Aug 31, 2009, 12:26:26 AM8/31/09
to clo...@googlegroups.com
On Sun, Aug 30, 2009 at 1:02 PM, Ivan Chernetsky <ivan.ch...@gmail.com> wrote:
2009/8/30 J. McConnell <jdo...@gmail.com>:


> What versions of Clojure and Clojure-Contrib are you using?

The freshest ones.

This appears to be the problem. If I use the HEAD version of Clojure, I get the same error and it goes away if I use the -lib argument.

The Ant tasks have only been tested against Clojure 1.0, since I assumed that's what most people would be using in a production context. I am thinking about going the Contrib route and tagging a 1.0-compatible version and updating everything to work against HEAD. Feel free to watch the repo on GitHub if you'd be interested in that.
 
I'm curious what may be the reason!

Me too ... I wonder what the difference could be that it works with the -lib argument and not without it. There was a change to clojure.lang.RT.baseLoader() after 1.0 that could be playing a role here. Thanks for pointing it out.

Regards,

- J.

Ivan Chernetsky

unread,
Aug 31, 2009, 4:39:50 AM8/31/09
to clo...@googlegroups.com
2009/8/31 J. McConnell <jdo...@gmail.com>:

> The Ant tasks have only been tested against Clojure 1.0, since I assumed
> that's what most people would be using in a production context.

For my personal projects the HEAD version is stable enough. :)

> I am
> thinking about going the Contrib route and tagging a 1.0-compatible version
> and updating everything to work against HEAD. Feel free to watch the repo on
> GitHub if you'd be interested in that.

OK, thank you!

Reply all
Reply to author
Forward
0 new messages