0

I'm trying out NetBeans for editing Groovy code. (I'm new to Groovy, and it's been a long time since I did any Java development).

At some point I installed the Groovy plugin via the "plugins" tool. But it does not have the green checkmark under "active", and choosing the Groovy plugin does not make the Activate/Deactivate/Uninstall buttons available. Oh well...

So let's create a project...

  1. Choose "new project". I'm choosing "Java with Maven" just because it's the first one.
  2. Hit "Finish"...and voila, I have a project.

Let's create a file...

  1. Right click the project package in the left pane, choose "new"
  2. Choose "Groovy Script" for a type, hit "finish"
  3. Hey, I have a very simple script. Looks like it should say "Hello chris!" when done.
  4. Hit the "play" button on the toolbar....things appear in the output window.

But wait a minute...the output is "Hello World!", and it should be "Hello chris!" It looks like "HelloWorld" is coming out of "Mavenproject1.java".

How can I (or can I) just run my script from within NetBeans?

UPDATE: per @andrewJames suggestion, I tried working that tutorial. (It looks like the tutorial may be a bit out of date.)

  1. I created a "Java Ant" project, as that was the only one that offered me the option of not creating a "Main Class File".
  2. I created the Java form, and the Groovy class, as directed.
  3. When I run the project, I get an error message saying "Error running forked groovyc".

I get that same error whether I'm running on a machine with a groovyc executable or not, so I suspect that there's something about the configuration that I need to change in order to point to the groovyc executable.

Probably something to do with the build.xml file...but I can't seem to figure out how to edit that to change the search path for the groovyc step.

1
  • Which version of NetBeans are you using? For example, with the latest version (v13) you do not need to install a plugin. Groovy will be activated automatically the first time you attempt to use it. See this demo for an example. It's different from what you are trying to do, (the example uses a Groovy class, not a script) but may help anyway. Commented Apr 26, 2022 at 21:56

1 Answer 1

1

I had the same problem that NB doesn't run a Groovy script out of the IDE like Eclipse does. I logged an issue and spent more than a year on the netbeans-dev mailing list advocating for it. Often replied to with "we'll be happy to review your pull request" type of stuff. Eventually, when I rage quit the mailing list with a scathing message, Geertjan replied to the issue with a solution.

So, in short, use the old plugin to create a Groovy project and change line 26 in groovy-build.xml to

<groovyc srcdir="@{srcdir}" sourcepath="@{sourcepath}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" includeAntRuntime="true" fork="false">

You can then run your script with Shift+F6.

The project needs the Groovy jars added. It works for me on NB 11, 12 & 13 with Groovy 2.x and Java 8, 11 & 14 so far. I haven't tried it with Groovy 3.x as the groovy-all.jar is deprecated so you'll have to maven or manually manage the Groovy jars.

Also, I collaborated a bit with someone on a new plugin. It works as is but new development has stalled.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.