How to use groovy inside a Eclipse RCP project? - groovy

I have a Eclipse RCP project, and I want to use Groovy inside it. what I try to do is :
1) add "Groovy Nature"
2) create Groovy files under the "src" folder
3) call the groovy class from the "View"'s createPartControl() method.
But I got the “java.lang.ClassNotFoundException: fly.island.jface.Test”, and the "fly.island.jface.Test" is a groovy class.
What should I do to use groovy inside the Eclipse RCP project?

Use the latest version of Groovy-Eclipse 2.1.0 (or one of the dev builds). Update site is here:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/
Additionally, there are some steps you need to do to compile the groovy plugins when you the PDE build. I'd recommend reading:
http://contraptionsforprogramming.blogspot.com/2010/08/groovy-pde-redux.html
Essentially, you need to include the org.codehaus.groovy bundle in your rcp app, and then you need to make some changes to the build.properties file of your Groovy plugins (explained in detail on the blog post).

Are you using the latest Version of eclipse (3.6) and the groovy plugin? I recall occasionally having problems with the Java and Groovy compilers not finding each other's classes (in the first version of the plugin, it took a lot of fiddling and luck to get it to work at all). The most recent version seems to be pretty good in that regard, though I've been using it only for a few days myself.

Related

How to use Mockito in a simple java project without Maven and Gradle

Can we use the Mockito framework in a simple Java project without maven and Gradle? I saw many youtube videos but all of them use either Maven or Gradle. I do not understand why they do not use it in a simple java project.
Can we use the Mockito framework in a simple Java project without maven and Gradle? I saw many youtube videos but all of them use either Maven or Gradle. I do not understand why they do not use it in a simple java project.
Yes. People do this every day as this. It's the 'normal' way to use Mockito.
Here is an example project that uses an older version of mockito, but the concept is still the same: https://java2blog.com/mockito-junit/

Upgrading Liferay 6.2 maven plugins into Liferay 7 module

There are many sites which provides articles for upgrading liferay 6.2 to dxp but only for ant project. How can we upgrade liferay 6.2 maven project to liferay dxp gradle project ?
The strategy to upgrade your code is exactly the same. Liferay's Plugins SDK defaulted to Ant until 6.2, now you have the choice between liferay-workspace (gradle based), gradle and maven - just choose the build environment you'd like (sounds like you'd like to continue with maven) and add your code to an empty blueprint for the project of your choice.
There's an upgrade tool in Liferay IDE that might help you - even if it doesn't use the build tool of your choice or if eclipse isn't the IDE of your choice: The upgrade tool is a one-off tool to use during upgrade. No matter what the result is on: You can always check (for example) Liferay's blade-sample project to find the proper build descriptors for Maven - and adapt them to your project.
Edit: After the clarification: Your main task is still the upgrade of the code. As of moving from Maven to gradle: Identify the dependencies and translate from pom.xml syntax to gradle's declaration - the contents are similar (e.g. group, name, version), only how you're writing them down is different. If you have made elaborate custom modifications to your pom.xml try to go without them first. You can start with a stock build.gradle (e.g. from blade-samples that most closely match your project) and then fix compile-time dependencies as you go.
I'm not aware of an automated process that does this translation for you (and most likely you'd bump up a few version numbers in the process anyway)

Is it possible to use Groovy with Spring Roo?

Is there a way to use Groovy in a Spring Roo project?
I'm using STS (Eclipse) and I'd like to be able to write some code in Groovy
and use Spock framework for unit testing.
But it seems, there are some problems with AspectJ and Groovy intergation.
Has anyone successfully used Roo and Groovy together?
Thanks.
Unfortunately you cannot mix those two languages in the same project.
When you installed Groovy-Eclipse you install a patched eclipse java compiler that is then able to build java and groovy code. When you install AspectJ you get an alternative compiler that can build java and AspectJ source (your Roo projects are AspectJ projects).
In a Roo project it will be using the AspectJ compiler and not the patched java compiler installed via Groovy-Eclipse, so it won't understand groovy code.
The proper solution is to patch AspectJ in the same way Groovy-Eclipse is done so AspectJ can build groovy+java+aspectj but we still haven't gotten around to that.
The easiest thing for you to do is split the tests into a separate Groovy test project that depends on the Roo project containing the main sources. That should work.

Gradle fails to find JavaFX classes

I am on a Linux Mint machine where I installed the latest version of Java (HotSpot VM 1.7.0_45) and using Gradle 1.8.
I also have Groovy installed, version 1.8.6, but I think that does not matter as Gradle has its own groovy-all.jar.
My problem is that I could not compile my Groovy project using gradle because the JavaFX classes do not seem to be in the classpath. The errors are like this:
unable to resolve class javafx.scene.Node
# line 3, column 1.
import javafx.scene.Node
I finally fixed this by adding the following horrible hard-coded path into my dependencies:
compile files( "/usr/lib/jvm/java-7-oracle/jre/lib/jfxrt.jar" )
Is there a better way to add JavaFX to Gradle's compilation classpath so that it is visible to all my projects without me having to add this to each one of them??
I have tried everything I could imagine:
added the jfxrt.jar to the standard JRE (I confirmed gradle is using my standard java to run) ext folder, so that I now can compile java classes with javac and run them with java (I know that in this version of Java the JavaFX jar should be already in the JDK's classpath, but I still couldn't RUN, as opposed to compile, my Java app before doing this).
also added a soft link to the same jar in the groovy classpath, so that I can do something like shown below from the groovy shell and it works:
import javafx.application.Application as A ; println A
This also works in the Groovy Console.
It only does not work in Gradle!
Thanks for any help.
Use the JavaFX Gradle Plugin.
The JavaFX Gradle Plugin should be able to work out where the JavaFX runtime is located without you having to perform manual, environment specific configuration.
For further information on JavaFX classpath resolution (not Gradle related), see:
Compile code using JavaFX 2.0 (using command line).
Also note, if you are using Oracle Java 8 or newer, JavaFX classes are now on the default runtime classpath for an Oracle Java implementation.
Incidentally, the build system for the entire JavaFX system is based on Gradle, so there is definitely no incompatibility between JavaFX and Gradle.

Can a groovy code be compiled to run in JRE?

I am new to groovy and I cannot understand, if it is possible to compile a groovy program, so it runs at all computers, were the JRE is installed.
The application I am developing has to run on any computer with JRE 1.5. Is it possible to start using groovy and maintain this flexibility? With JRE 1.6?
I have heard about the library groovy-all-VERSION.jar. Is this the one required library to be shipped with my application?
The answer is yes. In fact, all groovy code compiles down to Java classes that run on the JRE. All you need is JRE 1.4 or higher and the groovy-all-*.jar on the classpath of your application.
Since you are looking to support JRE 1.5 or higher, make sure your source compatibility is set on your compiler to this level.
There are a few options for compiling your groovy code. Groovyc (Ant Task), GMaven (Maven) and Gradle are all options.
Another option you have is to 'not' compile your groovy code. The groovy distribution only requires the JRE to be installed. You can ship your application as a set of scripts that can simply be run using the groovy install. It depends on how sensitive your source code is.
The short answer is yes. How you do this depends on your build system. I do all my development in eclipse, right click my project, select export, select runnable jar file, and all the required librarys are exported in the jar file. I can then run this file on a machine with out Groovy installed. I know build systems like Maven support Groovy but don't know the details on how they do it or how good there support is. According to this question Java 1.4 or above is fine. When looking at the "Setting up your Java environment" section of the initial tutorial it looks like you need Java 1.5 installed.

Resources