Jython Interoperability problem

48 views
Skip to first unread message

Dilvan

unread,
Oct 29, 2010, 10:41:17 AM10/29/10
to Clojure
Hi,

It was possible in clojure 1.0.0 to include clojure Persistent
collections in Jython:

jython -Dpython.path=<clojure_dist>/clojure_1.0.0/clojure-1.0.0.jar

>>>from clojure.lang import PersistentList
>>>b= PersistentList.create([7, 8, 2])
>>>b
(7 8 2)

But with clojure 1.1.0 or 1.2.0 I get:

jython -Dpython.path=<clojure_dist>/clojure-1.2.0/clojure.jar

>>> from clojure.lang import PersistentList
>>> b= PersistentList.create([7, 8, 2])
>>> b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
java.lang.ExceptionInInitializerError
at clojure.lang.ASeq.toString(ASeq.java:20)
at org.python.core.PyJavaType$5.__call__(PyJavaType.java:542)
at org.python.core.PyObjectDerived.__repr__(PyObjectDerived.java:63)
at org.python.core.PySystemState.displayhook(PySystemState.java:1190)
at org.python.core.PySystemStateFunctions.__call__(PySystemState.java:
1257)
at org.python.core.PyObject.invoke(PyObject.java:3583)
at org.python.core.Py.printResult(Py.java:1748)
at org.python.pycode._pyx5.f$0(<stdin>:1)
at org.python.pycode._pyx5.call_function(<stdin>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1204)
at org.python.core.Py.exec(Py.java:1248)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:181)
at
org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:
89)
at
org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:
70)
at
org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:
46)
at org.python.util.InteractiveConsole.push(InteractiveConsole.java:
110)
at
org.python.util.InteractiveConsole.interact(InteractiveConsole.java:
90)
at org.python.util.jython.run(jython.java:316)
at org.python.util.jython.main(jython.java:129)
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:305)
... 21 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:412)
at clojure.lang.RT.load(RT.java:381)
at clojure.lang.RT.doInit(RT.java:416)
at clojure.lang.RT.<clinit>(RT.java:302)
... 21 more

java.lang.ExceptionInInitializerError:
java.lang.ExceptionInInitializerError

Any clues?

Mikhail Kryshen

unread,
Nov 1, 2010, 7:24:38 PM11/1/10
to clo...@googlegroups.com
Consider using some implementation of persistent data structures that
does not depend on Clojure.

Clojure's data structures modified for use outside of Clojure:
http://github.com/krukow/clj-ds

Persistent analogue of the Java Collections Framework:
http://code.google.com/p/pcollections/

--
Mikhail

Dilvan

unread,
Nov 8, 2010, 8:21:30 AM11/8/10
to Clojure
Hi,

Thanks a lot for your reply. I thought Java interoperability was
one of the key points for Clojure "a language for the JVM", having a
pure Clojure version that limits interoperability in the JVM isn't
quite in this spirit.

The first project (clj-ds) seems quite what I need now, but I would
like to be able to use the libraries shipped with Clojure. They are
more likely to be around for the long run. Do you know how can I
"bootstrap" Clojure before using any Clojure specific data structure
(from Java or Jython)? The 1 second start-up time and slower
performance for large structure, when compared to clj-ds, aren't an
issue for me right now.

Rasmus Svensson

unread,
Nov 9, 2010, 3:41:01 AM11/9/10
to clo...@googlegroups.com
2010/10/29 Dilvan <dil...@gmail.com>:
>   Any clues?

I don't know much about how Jython works, but from the stack trace it
seems like Clojure cannot load its source files from the classpath.
Are there other ways to add jars to the classpath in Jython?

// raek

Rasmus Svensson

unread,
Nov 9, 2010, 4:04:30 AM11/9/10
to clo...@googlegroups.com
It seems like this is a class loader issue... The guys working on
clojure-ant-tasks seems to have hit the same problem:

https://github.com/jmcconnell/clojure-ant-tasks/issues#issue/5/comment/223478

I also found these two issues:

http://dev.clojure.org/jira/browse/CLJ-260

http://dev.clojure.org/jira/browse/CLJ-379

It seems like it should be possible to make a workaround, but
unfortunately I don't have any experience at all with how class
loaders work. So I'm afraid I'm out of advice...

// raek

Dilvan

unread,
Nov 9, 2010, 6:47:22 PM11/9/10
to Clojure
On Nov 1, 9:24 pm, Mikhail Kryshen <mikh...@kryshen.net> wrote:
> Clojure's data structures modified for use outside of Clojure:http://github.com/krukow/clj-ds
>
> Persistent analogue of the Java Collections >Framework:http://code.google.com/p/pcollections/

These libraries only cover persistent collections (lists,
hashtables, etc). I am also using clojure.lang.Ref class (to implement
STMs).
Are there any libraries that implement clojure.lang.Ref outside
Clojure? Or does anyone knows how to "bootstrap" Clojure before
creating any object from a persistent collection class? Ref objects
seem to be working without any need for a "bootstrap".

--
Dilvan Moreira
http://java.icmc.usp.br dil...@icmc.usp.br

Alex Osborne

unread,
Nov 20, 2010, 10:11:12 PM11/20/10
to clo...@googlegroups.com
Dilvan <dil...@gmail.com> writes:

> Do you know how can I "bootstrap" Clojure before using any Clojure
> specific data structure (from Java or Jython)?

It seems to be fine if you put it on the Java system classpath instead
of python.path:

$ jython -J-cp clojure-1.2.0.jar
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_22
Type "help", "copyright", "credits" or "license" for more information.

Dilvan

unread,
Nov 21, 2010, 8:00:22 PM11/21/10
to Clojure
Thanks, it works for me.
Reply all
Reply to author
Forward
0 new messages