Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h1>Overview</h1> <p>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:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> ikvmc -target:library groovy-all-1.5.0.jar </pre></td></tr></table> <p>However, some warning will appear, but you can ignore them. After compilation you should have <strong>groovy-all-1.5.0.dll</strong> in the current directory.</p> <h1>Using the Groovy .NET Assembly</h1> <p>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 <a href="http://www.icsharpcode.net/OpenSource/SD">SharpDevelop</a> IDE in this case.</p> <ul> <li>Open SharpDevelop, create a new .NET console application.</li> <li>Add references, your groovy DLL, and all IKVM DLLs.</li> <li>Open your main class, type the following code (in C# for example)</li> </ul> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> using System; using System.Collections.Generic; namespace GroovyDotNet { class MainClass { public static void Main(string[] args) { groovy.ui.InteractiveShell.main(args); } } } </pre></td></tr></table> <ul> <li>Run the program, and you'll also have an executable file as well (in ./Debug directory).</li> </ul> <p>the original post: <a class="external-link" href="http://chanwit.blogspot.com/2007/04/groovy-running-fine-on-net.html" rel="nofollow">http://chanwit.blogspot.com/2007/04/groovy-running-fine-on-net.html</a></p> <h1>Invoking .NET classes</h1> <p>We can call .NET classes directly from Groovy scripts. Note that IKVM has the <strong>cli</strong> prefix for all .NET namespaces. If you want to invoke <strong>Console.WriteLine('hello world')</strong>, you have to type:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> cli.System.Console.WriteLine('hello world') </pre></td></tr></table> <p>The great thing here is that Groovy can pick a correct .NET method. You can also try:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> cli.System.Console.WriteLine('hello world {0}', 'from Groovy') </pre></td></tr></table> <p>in the interactive console (the binary in the attachment of this page).</p> <h2>Encoding Issues</h2> <p>On some machines, there will be a test encoding issue to stop Groovy compiling script files. This seems to be the use of different encoding names between Java and .NET. If you find this kind of error, try specifying "-c" when testing with groovy.ui.GroovyMain class.</p> <h2>Further development as a Groovy module?</h2> <p>Discuss <a class="confluence-link unresolved" data-content-title="Groovy.Net module discussion" data-linked-resource-default-alias="Groovy.Net module discussion" href="#">here</a>.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced