Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running stand-alone groovy script from netbeans

I have bunch of groovy scripts in various directories (not necessarily netbeans/maven project dirs). I have been using Notepad++ and Netbeans to create/edit these scripts. I favorite the directories containing scripts in NB so that I can open it in NB (from the favorites tree) without having to have a java project. I usually fire-up cygwin thorugh putty-cyg to execute/test these scripts. Netbeans offers a decent terminal as well within IDE where i can issue commands without ALT-TAB'ing the IDE and Putty-Cyg. All is working nicely.

Just thought how nice it would be if I could have a Run Script in the context menu where I can run a script (and optionally it may ask for scripts arguments too). This would save a lot of ALT-TABing and cd'ing into scripts directory and typing groovy scriptname.groovy.

  1. Can anyone suggest any plugin that allows me to do so?
  2. If I have to write my own plugin for that same task, how should I start? (I checked out nb plugin/platform docs, its overwhelming).
  3. If someone is in same situation as I, feel free to share experiences.

pros/cons of NPP : fast / no auto-complete, its not IDE, no lang support for groovy

pros/cons of NB : everything at one place, lang support, somewhat auto-completes for groovy/ bit sluggish, takes time to start up, you must be in java (ant/maven) project directory to reap most of IDE benefits

Eclipse support is okay but it does not do what i am asking above. I am downloading IDEA community edition to check its support. (UPDATE: Nope it doesn't. I tried it)

like image 736
kdabir Avatar asked Jun 28 '11 19:06

kdabir


People also ask

How do I run a Groovy script in Java?

With the GroovyClassLoader we can load Groovy scripts and run them in Java code. First we must create a new GroovyClassLoader and then parse a Groovy script. The script can be in a file, string or inputstream. Once the script is parsed we have a Class and we can make a new instance of this class.

How do I run a Groovy script?

To run a Groovy script, from the context menu in the editor, select Run 'name' Ctrl+Shift+F10 .


1 Answers

I feel your pain. I don't know if this is the best solution but this is what my team has done.

GroovyConsole Groovy does come with a handy tool called Groovy Console where you can quickly play around with scripts. This is our primary tool if we want to quickly create or edit scripts. We setup our workstations to open all .groovy files in the Groovy Console which makes it painless and easy to test. It doesn't have code completion which is fine for us because it's a dynamic language and it doesn't really help; in most cases it just slows you down waiting for the suggestion to pop up anyways (NetBeans).

Existing NetBeans Plugin Here is a plugin for NetBeans that brings the Groovy Console inside the IDE. I haven't used it so an can't really speak for it but it seems like it could be useful.

Creating your own Plugin I've built a couple NetBeans plugins before and the first one is always the hardest because you can't just dive in and creating one. You'll really have to read the documentation to understand how things work. Don't try to just 'figure it out' (speaking form experience!).

Hope this helps!

like image 133
Michael J. Lee Avatar answered Sep 19 '22 21:09

Michael J. Lee