Overview
It is possible to run Groovy on .NET 2.0 using IKVM as a virtual machine. By using IKVM compiler, you can compile your Groovy jar to be a .NET assembly (a DLL file) with the following command:
However, some errors will appear, but you can ignore them. After compilation you should have groovy-all-1.1-SNAPSHOT.dll in the current directory.
Using the Groovy .NET Assembly
With the compiled DLL, you can use it as a normal .NET assembly. The following example shows how to add it as a reference for building a simple application. You need the SharpDevelop IDE in this case.
- Open SharpDevelop, create a new .NET console application.
- Add references, your groovy DLL, and all IKVM DLLs.
- Open your main class, type the following code (in C# for example)
- Run the program, and you'll also have an executable file as well (in ./Debug directory).
the original post: http://chanwit.blogspot.com/2007/04/groovy-running-fine-on-net.html
Invoking .NET classes
We can invoking .NET classes directly from Groovy scripts. Note that IKVM has a cli prefix for all .NET namespaces. If you want to invoke Console.WriteLine('hello world'), you have to type:
The great thing here is that Groovy can pick a correct .NET method. You can try:
in the interactive console (the binary in the attachment of this page).
Further development as a Groovy module
Should this be a Groovy Module? It is possible by providing a number of EXE files for invoking Groovy services (groovyc, groovy console, etc.). One important thing is that the process of compiling Groovy files into .NET DLL is a bit tricky. We can compile Groovy files into .classes using groovyc, then we have to pack them into a jar file, and finally call ikvmc to compile the jar in to a DLL.