ikvm and .NET

42 views
Skip to first unread message

Mark J P

unread,
Oct 22, 2008, 11:30:10 AM10/22/08
to Clojure
Steps for running clojure as a .NET app and instantiating .NET types.

- I converted the clojure.jar to clojure.dll: ikvmc -target:library c:
\path\to\clojure.jar (this creates clojure.dll)
- Convert mscorlib.dll to mscorlib.jar: ikvmstub mscorlib.dll
- Create a .net c# console app, and add reference to clojure.dll
- Change Main to this:
static void Main(string[] args)
{
clojure.lang.Repl.main(new string[] {});
}
- Run console app (Repl) and add mscorlib.jar to classpath via
clojure: (add-classpath file://c:.....)

Now you can instantiate .net types
(def i (new cli.System.Int32))
(def s (new cli.System.String nil))

Mark J P

unread,
Oct 22, 2008, 12:26:39 PM10/22/08
to Clojure
hmmm, the .NET String thing isn't quite working for some reason.
Seems like it converts to the java string. I can work with
StringBuilder though:

(def sb (new cli.System.Text.StringBuilder))
(. sb (Append "asdf"))

Mark J P

unread,
Oct 22, 2008, 1:55:19 PM10/22/08
to Clojure
Forgot to include this step:

Add a reference to IKVM.OpenJDK.ClassLibrary.dll in the .NET Project


On Oct 22, 11:30 am, Mark J P <PsiColla...@gmail.com> wrote:

Shawn Hoover

unread,
Oct 22, 2008, 3:41:37 PM10/22/08
to clo...@googlegroups.com
On Wed, Oct 22, 2008 at 8:30 AM, Mark J P <PsiCo...@gmail.com> wrote:

Steps for running clojure as a .NET app and instantiating .NET types.

- I converted the clojure.jar to clojure.dll: ikvmc -target:library c:
\path\to\clojure.jar  (this creates clojure.dll)
- Convert mscorlib.dll to mscorlib.jar: ikvmstub mscorlib.dll
- Create a .net c# console app, and add reference to clojure.dll

By the way, this is great for embedding Clojure in your .NET app. If all you want is a REPL, you can skip the C# app step and use the -target:exe switch to get a clojure.exe.

The topic has also been explored in a past thread: http://groups.google.com/group/clojure/browse_thread/thread/e48b64f3dc1f09fb/09919e06ebe95d85?lnk=gst.

Shawn
Reply all
Reply to author
Forward
0 new messages