Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy, Netbeans and Java EE

I want to develop a web application (no frameworks) mixing java with groovy. I am using the IDE Netbeans with the plugin.

If I start a new Java SE project and add a groovy class, it works with no problems.. but when I create a new java EE project and add a groovy class it can't compile and shows me the following error:

/home/webcodei/NetBeansProjects/testeGroovyWeb/src/java/pacote/Hello.java:23: cannot find symbol 

symbol  : class Hroovy
location: class pacote.Hello
            Hroovy h = new Hroovy();
/home/webcodei/NetBeansProjects/testeGroovyWeb/src/java/pacote/Hello.java:23: cannot find symbol
symbol  : class Hroovy
location: class pacote.Hello
            Hroovy h = new Hroovy();
2 errors
/home/webcodei/NetBeansProjects/testeGroovyWeb/nbproject/build-impl.xml:383: The following error         occurred while executing this line:
/home/webcodei/NetBeansProjects/testeGroovyWeb/nbproject/build-impl.xml:211: Compile failed; see     the compiler error output for details.
FALHA NA CONSTRUÇÃO (tempo total: 0 segundos)

Does anybody have a clue of how do I enable Java EE + Groovy in netbeans?

ps: I know the existence of Grails

ps2: The Groovy jar is in my classpath.

Thank you for all!

like image 419
José Leal Avatar asked Jan 06 '09 11:01

José Leal


People also ask

Does NetBeans support Groovy?

The Groovy support comes with NetBeans "Java" and "All" package. If your NetBeans does not have Groovy, download the plugin through NetBeans Plugin Manager. For more information about adding a new plugin, click IDE Basics > Plugins > Updating the IDE on the NetBeans Help menu.

How add Java EE to NetBeans?

Enabling Java EE support To install Java EE support, the NetBeans 8.2 update center repository should be added to the IDE. First, go to Tools > Plugins > Settings . Third, search for new plugins with the keyword "Kit." As the name suggests, these are plugin collections for specific purposes.

Does NetBeans 12 support Java EE?

The key new feature for Gradle users in Apache NetBeans 12.0 is its support for Java EE.


2 Answers

It appears that the NetBeans 6.5 Java Webapp project manager does not have the "Enable Groovy" support that is present in the Java App and Java Class library projects.

I can think of two ways you might get around this:

First, you could put your Groovy code and tests in a separate project as a Java Class Library. Then make the Java webapp dependent on the Groovy project. NetBeans will build the dependent project automatically so you'll hardly notice they are in separate projects.

Second, the "Enable Groovy" isn't magic. All it does is write a groovy-build.xml in /nbprojects and modify build-impl.xml to import it. The groovy-build.xml overrides the default "javac" macro to invoke "groovyc" instead. If you're at all handy with Ant, you could copy a groovy-build.xml from a Java Application project and copy it to your Java Web project and then import it from your build.xml (before build-impl.xml is imported). The groovy-build.xml would likely need a few tweaks as some of the properties between a webapp and class library are a little different.

like image 135
Dave Smith Avatar answered Sep 28 '22 04:09

Dave Smith


@Dave Smith,

This was exactly what I did. I created one javase project and one webapp and started to compare them. After a few minutes I realised that the only diference was the groovy-build.xml.

So I copied the groovy-build.xml into the dir, and inserted the following lines into my build.xml:

<import file="nbproject/groovy-build.xml"/>

Right before the regular

<import file="nbproject/build-impl.xml"/>

And then called the groovy file to overwrite the -init-macrodef-javac.

<target depends="-groovy-init-macrodef-javac" name="-pre-compile">

</target> 

I also needed to change the namespace from the groovy-build.xml to mine ex:

<macrodef name="javac" uri="http://www.netbeans.org/ns/web-project/2"> 

And inserted the j2ee classpath (${j2ee.platform.classpath}) to the attribute a few lines later:

<attribute default="${javac.classpath}:${j2ee.platform.classpath}" name="classpath"/> 

After that the project worked successfully! =D

Thank you for all!

like image 36
José Leal Avatar answered Sep 28 '22 04:09

José Leal