For those not familiar with Groovy its one of a surprisingly large group of languages whose source code is different from Java, and yet runs on the Java runtime. Java source code is compiled into Java bytecode which is executed by the Java Virtual Machine (JVM) on your computer. Groovy source code is also compiled into Java bytecode which then runs on the very same JVM. This allows the two languages to interoperate in interesting ways.
As a starting point for this tutorial I assume you have an existing Java based project, use Ant to build your system and use Eclipse as your development environment. None of that is required for Groovy but it is a fairly standard setup and its what I use, both at home and at work.
The steps are basically
a) download and install the Groovy GDK
b) add a how-to-compile-groovy task to your Ant build.xml (the task is included in the GDK)
c) add the groovy-all.jar file to your library path
d) add the groovy-plugin to your Eclipse project
e) enable groovy-nature in your Eclipse project
f) write a Groovy class and use it.
Overall this should take no more than twenty minutes or so. One of the really cool things is that once you have a Groovy class you can use it from your Java classes just like any other class...your Java code has no idea its using a class written in Groovy.
Now lets look at the steps listed above in cookbook manner.
a) go to http://groovy.codehaus.org/Download and select the latest stable release (currently 1.5.7). Click on the download link and follow the very simple instructions.
b) add the following task to your build.xml to define how to compile groovy code:
c) the Groovy GDK includes a groovy-1.5.7-all.jar file. Add this to your library and execute paths
d) From Eclipse, select Help, Software Updates, Find and Install, Search for new features to install, next.Now select New Remote Site. Enter Groovy as the Name and http://dist.codehaus.org/groovy/distributions/update as the URL.Press Ok and you should find Groovy added to the list of Sites to include in search. Press Finish.It should find Groovy, check the features you want and press Next.Accept the license terms and press Finish. At this point the plugin will be downloaded and installed.
e) From Eclipse select your proejct, right click and select Groovy->Add Groovy Nature. Eclipse will now understand files with the .groovy extension.
f) Remember that any Java file is also a Groovy file, so if you want to start with baby steps just rename one of your java files to have a groovy extension. Eclipse and Ant will recognize it and compile it to bytecode and then allow you to use it.
You could then take another small step and remove most of the semi-colons, because Groovy doesn't require them.If your class has import statements from various java packages you can probably remove them as well since Groovy automatically imports them.
Clearly you then want to write a class that actually uses Groovy features but that's beyond the scope of HelloGroovyInAJavaProjectWorld.
Enjoy.
Thanks! Just what I needed.
ReplyDeleteThanks!!!!
ReplyDeleteThanks alot too!
ReplyDeleteI highly recommend that you use Groovy-Eclipse 2.0 available from this update site:
ReplyDeletehttp://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.5/
Please do not use the update site listed in this blog post, it is for Groovy-Eclipse 1.5.7 (out of date now).
Interesting blog, i usally be aware all about all different kind of sofware. i am online all the time, and this action allow me to see a site costa rica homes for sale and i like it too much. beyond all doubt without my computer i never would have seen this site too.
ReplyDeleteGroovy is indeed a great addition to make your Java app more powerful.
ReplyDeleteinformative post thanks for sharing
ReplyDeleteandroif projects
final year projects with source code
informative post thanks for sharing
ReplyDeletenetworking projects
Very interesting information, worth recommending. However, I recommend this: additional reading
ReplyDeleteI wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. login no HappyMod
ReplyDeleteI am unable to read articles online very often, but I’m glad I did today. This is very well written and your points are well-expressed. Please, don’t ever stop writing. Writing Tools
ReplyDeleteI am unable to read articles online very often, but I’m glad I did today. This is very well written and your points are well-expressed. Please, don’t ever stop writing. writing software
ReplyDeleteHere you will learn what is important, it gives you a link to an interesting web page: CBT Bulk Email Sender
ReplyDeleteHere you will learn what is important, it gives you a link to an interesting web page: CBT Bulk Email Sender
If you are looking for more information about flat rate locksmith Las Vegas check that right away. پروژه ستین
ReplyDeleteWhatsApp Group Links
ReplyDeleteblog posts. Any way I'll be subscribing to your feed and I hope you post again soon
WhatsApp Group Links
Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. flexispy
ReplyDeleteAs a seller of legal steroids, you can buy Crazy Bulk products, explore stacks and finally get the body you’ve always wanted vape attic olathe
ReplyDeleteThis is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. spy apps for android
ReplyDeleteThis is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. top trending twitter
ReplyDeleteThank you, for technologies and academic projects visit our website
ReplyDeleteJava Projects for Engineering Students on Takeoff Edu Group.