Discussion:
Adding Maven dependencies to a Groovy project
dead_passive
2009-12-18 15:02:42 UTC
Permalink
Hi,

I've got a plain old Java Project in Netbeans which I'm using to run my Groovy code. However, I need to add a Maven dependency. How do I go about adding dependencies to a Java/Groovy project in Netbeans?

When I was using Eclipse I just did it all on the command line (calling "mvn install" whenever I need an update). Eclipse would then show the dependencies I needed after a refresh.

I'm new to Netbeans but I see that it has Groovy support (better than Eclipse which I'm having trouble with) and Maven support so was hoping it would make things easier...

Cheers,

Jon
mkleint
2009-12-20 19:35:08 UTC
Permalink
you need to use groovy within a maven project. Cannot add maven to ant
project (plain old Java project)..

Milos
Post by dead_passive
Hi,
I've got a plain old Java Project in Netbeans which I'm using to run my Groovy code. However, I need to add a Maven dependency. How do I go about adding dependencies to a Java/Groovy project in Netbeans?
When I was using Eclipse I just did it all on the command line (calling "mvn install" whenever I need an update). Eclipse would then show the dependencies I needed after a refresh.
I'm new to Netbeans but I see that it has Groovy support (better than Eclipse which I'm having trouble with) and Maven support so was hoping it would make things easier...
Cheers,
Jon
dead_passive
2010-01-05 15:43:58 UTC
Permalink
Hi,

Sorry for the late reply, I've been away from Christmas.

I've created a Maven project (New Project -> Maven -> Maven Project -> Maven Quickstart Archetype) and added a Groovy script. When I run the project, however, it doesn't work. I think the problem is that it's trying to run my Groovy as if it was Java. The problem in the Maven out is:

[ERROR]BUILD ERROR
------------------------------------------------------------------------
Result of cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_16\bin\java.exe" -classpath D:\JavaProjects\NetBeansProjects\NormalQuickstart\target\classes com.mycompany.normalquickstart.NewGroovyScript" execution is: '1'.

Am I doing something wrong? Any help would be greatly appreciated.

Thanks,

Jon
dead_passive
2010-01-05 15:45:12 UTC
Permalink
BTW I'm using Netbeans 6.8.
mkleint
2010-01-07 07:01:48 UTC
Permalink
I'm not fluent with groovy, but does the script have a main() method? if
so, it should work (I recall testing it once).

Milos
Post by dead_passive
Hi,
Sorry for the late reply, I've been away from Christmas.
[ERROR]BUILD ERROR
------------------------------------------------------------------------
Result of cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_16\bin\java.exe" -classpath D:\JavaProjects\NetBeansProjects\NormalQuickstart\target\classes com.mycompany.normalquickstart.NewGroovyScript" execution is: '1'.
Am I doing something wrong? Any help would be greatly appreciated.
Thanks,
Jon
dead_passive
2010-01-07 10:56:23 UTC
Permalink
It doesn't have a main method, no. A Groovy script doesn't need one, it just runs as it is.

I am wondering if this is a bug?

Jon
mkleint
2010-01-08 05:08:25 UTC
Permalink
Post by dead_passive
It doesn't have a main method, no. A Groovy script doesn't need one, it just runs as it is.
I am wondering if this is a bug?
Jon
no it's not as far as I can tell, you just have to redefine the Run file
action to make it run. I guess there's some groovy entry main class for
running scripts..

Milos
dead_passive
2010-01-08 12:15:45 UTC
Permalink
Post by mkleint
no it's not as far as I can tell, you just have to redefine the Run file
action to make it run. I guess there's some groovy entry main class for
running scripts..
I've tried changing the Run Project action under Project Properties -> Actions. The original command was:


Code:
exec.classpathScope=runtime
exec.args=-classpath %classpath com.mycompany.normalquickstart.NewGroovyScript
exec.executable=java



I changed "java" to "groovy" and Maven at least tried to run my project correctly:


Code:
Caught: java.io.FileNotFoundException: D:\JavaProjects\NetBeansProjects\NormalQuickstart\com.mycompany.normalquickstart.NewGroovyScript (D:\JavaProjects\NetBeansProjects\NormalQuickstart\com.mycompany.normalquickstart.NewGroovyScript)
------------------------------------------------------------------------
[ERROR]BUILD ERROR
------------------------------------------------------------------------
Result of cmd.exe /X /C "groovy -classpath D:\JavaProjects\NetBeansProjects\NormalQuickstart\target\classes com.mycompany.normalquickstart.NewGroovyScript" execution is: '1'.



As you can see, it's trying to run "com.mycompany.normalquickstart.NewGroovyScript" which would work if it was a a Java class, however Groovy needs access to the source file instead (because it's a script).

Any idea how I can modify this so that it runs the source file and looks like the following:


Code:
groovy -classpath D:\JavaProjects\NetBeansProjects\NormalQuickstart\target\classes D:\JavaProjects\NetBeansProjects\NormalQuickstart\src\main\groovy\com\mycompany\normalquickstart\NewGroovyScript.groovy



Any help would be greatly appreciated!

Cheers,

Jon
mkleint
2010-01-11 07:46:27 UTC
Permalink
I suppose you want to use the groovy:execute goal, instead of the
generic exec:exec one.
http://groovy.codehaus.org/gmaven-generated/gmaven-plugin/execute-mojo.html
http://docs.codehaus.org/display/GMAVEN/Executing+Groovy+Code#ExecutingGroovyCode-ExecuteaLocalGroovyScript

I'm not entirely sure the groovy goal supports configuration via cmd
line properties (I guess an enhancement to be filed here), so you might
need to add the snippet from the 2nd url into your pom and make it
configurable via a custom property of yours.

Milos
Post by dead_passive
Post by mkleint
no it's not as far as I can tell, you just have to redefine the Run file
action to make it run. I guess there's some groovy entry main class for
running scripts..
exec.classpathScope=runtime
exec.args=-classpath %classpath com.mycompany.normalquickstart.NewGroovyScript
exec.executable=java
Caught: java.io.FileNotFoundException: D:\JavaProjects\NetBeansProjects\NormalQuickstart\com.mycompany.normalquickstart.NewGroovyScript (D:\JavaProjects\NetBeansProjects\NormalQuickstart\com.mycompany.normalquickstart.NewGroovyScript)
------------------------------------------------------------------------
[ERROR]BUILD ERROR
------------------------------------------------------------------------
Result of cmd.exe /X /C "groovy -classpath D:\JavaProjects\NetBeansProjects\NormalQuickstart\target\classes com.mycompany.normalquickstart.NewGroovyScript" execution is: '1'.
As you can see, it's trying to run "com.mycompany.normalquickstart.NewGroovyScript" which would work if it was a a Java class, however Groovy needs access to the source file instead (because it's a script).
groovy -classpath D:\JavaProjects\NetBeansProjects\NormalQuickstart\target\classes D:\JavaProjects\NetBeansProjects\NormalQuickstart\src\main\groovy\com\mycompany\normalquickstart\NewGroovyScript.groovy
Any help would be greatly appreciated!
Cheers,
Jon
dead_passive
2010-01-12 11:29:22 UTC
Permalink
In face, it seems to call groovy:execute before anything else is done (even compile:compile). I guess I need to change this too.

Jon
dead_passive
2010-01-12 16:42:08 UTC
Permalink
Is there any way to just replace the exec:exec command with the groovy:exec one? I've been messing around for ages now and I can't find a way of doing it.

Thanks,

Jon
mkleint
2010-01-12 20:23:16 UTC
Permalink
just change it in the Actions panel in project customizer?

Milos
Post by dead_passive
Is there any way to just replace the exec:exec command with the groovy:exec one? I've been messing around for ages now and I can't find a way of doing it.
Thanks,
Jon
dead_passive
2010-01-12 11:27:24 UTC
Permalink
Hi,
Thanks for the response.

I added the snippet from the 2nd link you posted to my POM and changed the path to my Groovy script. Now, when I run my project it calls groovy:execute and seeems to work ok. However, it still calls exec:exec too and comes up with the same NoClassDefFoundError. How can I stop it calling exec:exec?

Cheers,

Jon
dead_passive
2010-01-13 11:39:45 UTC
Permalink
Do you mean Project Properties -> Actions?

I've tried changing the Run project part but it keeps switching back to the original command.

Jon

Loading...