How to capture addiction and make it work with IntelliJ project?

I am trying to run a GroovyFX project in IntelliJ 12. However, I was unable to get IntelliJ to compile and run the following simple script (to reproduce the problem as much as possible):

@Grab(group='org.codehaus.groovyfx', module='groovyfx', version='0.3.1') import groovyx.javafx.GroovyFX println GroovyFX.class.name 

I used IntelliJ support for Grape Grab to add groovyfx depending on my module (the jar is shown in the External Libraries section, and the editor does not complain that it is missing after this class!), But still, when I run the script, it gives an error :

Groovyc: unable to solve groovyx.javafx.GroovyFX class

I was able to get this script running in GroovyConsole without much trouble and as expected ....

I tried to capture another randomly selected dependency (getting the Spring library) and it worked directly:

 @Grab(group='org.springframework', module='spring', version='2.5.6') import org.springframework.jdbc.core.JdbcTemplate println JdbcTemplate.class.name 

I see no good reason why the Spring library should work, but not the GroovyFX library !!!!

I even double checked that the GroovyFx library was actually loaded, and it is where it should be (under {user.home} /. Groovy / grapes / {group} / {module} / jars /)

What can cause this strange and extremely unpleasant problem?

+4
source share
1 answer

I tested your problem with both groovyConsole (from groovy -sdk-2.1.0 ) and IntelliJ IDEA 12.0.3. The only exception I got:

 Caught: java.lang.NoClassDefFoundError: javafx/application/Application java.lang.NoClassDefFoundError: javafx/application/Application at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) Caused by: java.lang.ClassNotFoundException: javafx.application.Application ... 1 more 

This is because the JavaFX runtime (jfxrt.jar) was not in the classpath. This can be fixed with

 mvn com.zenjava:javafx-maven-plugin:1.3:fix-classpath 

The above command is taken from the JavaFX Maven Plugin Wiki . You must execute it only once. After that, both groovyConsole and IntelliJ work. I had to restart groovyConsole, this was not necessary for IntelliJ.

Interestingly, I do not see GroovyFx-jar in the External Libraries section. I am using the free version of the IDEA community without any plugins.

Hello World from the GroovyFX main page works out of the box in IDEA, but not in groovyConsole - I also get "java.lang.ClassNotFoundException: groovyx.javafx.GroovyFX". I managed to run it with the following code, but this is not a good solution, since it only works on the first start, then you need to restart groovyConsole:

 @GrabConfig(systemClassLoader=true, initContextClassLoader=true) @Grab(group='org.codehaus.groovyfx', module='groovyfx', version='0.3.1') import static groovyx.javafx.GroovyFX.start start { stage(title: 'GroovyFX Hello World', visible: true) { scene(fill: BLACK, width: 500, height: 250) { hbox(padding: 60) { text(text: 'Groovy', font: '80pt sanserif') { fill linearGradient(endX: 0, stops: [PALEGREEN, SEAGREEN]) } text(text: 'FX', font: '80pt sanserif') { fill linearGradient(endX: 0, stops: [CYAN, DODGERBLUE]) effect dropShadow(color: DODGERBLUE, radius: 25, spread: 0.25) } } } } } 

I am not sure, but I think the reason for this is the error here . Must be fixed in Groovy 2.2, we will see.

+5
source

All Articles