Can a groovy code be compiled to run in JRE? - groovy

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.

Related

How do you know the version of Java for a give repository?

When I'm going to compile a repository it seems I must guess which version of Java is intended. For example, if I want to compile elasticsearch I read the readme and execute ./gradlew assemble. Eventually the build fails because I have Java8 and it requires Java11. It is a simple change, but is there a way for me to ask gradle (or maven, when applicable) for the version of Java before I start to compile?
How does developer tools deal with this? They can't possibly just try random versions of JDK until something works. Is it always manual?
You generally look at source and target for maven-compiler-plugin in Maven so you should be able to look at that:
Specify JDK for Maven to use.
And as stated, JDK is backwards-compatible so you can compile with the latest JDK. Maven uses the JAVA_HOME variable by the way.

Is IBM Maximo 7.6 businessobject jar compiled in Java 1.8 compatible to run in java 1.7?

I have got jar compiled in java 1.8 from maximo dir and on my machine i have java 1.7 installed do i need to update my machine java before i run this jar. I can not run it before knowing this since it will get recorded in some logs and will update some server side files.
This is more of a Java question than a Maximo question, but no, it will not. You will get an "Unsupported major.minor version 52.0" if you do. This is not because of any features issue, this is simply because the bytecode is tagged as being from Java 8 and so earlier JREs will not run it.
Now this assumes you actually compiled the class files using Java 8, which probably only happened if you have custom code in there. If you are just using the out-of-the-box Maximo classes, those came pre-compiled (in I don't recall which version of Java) and so all you might have done was to bundle them into a jar, or more likely into the Maximo ear (since you don't run the businessobjects.jar). In that case, it doesn't matter what version of Java you used to created the jar/ear, it will run on any version of Java that is the same as or higher than whatever version IBM used to compile the code into classes.

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.

jdk1.7's javac can't find javafx jar without -cp option

I've read several questions on this site and elsewhere that indicate that when Oracle JDK7 is installed, it should not be necessary to specify the classpath to jfxrt.jar when the JDK is installed correctly. Unfortunately, my installation does not seem to be correct, but I cannot figure out what is wrong.
I used the correct RPM for my Red Hat Enterprise Linux 6.2 Server and I'm able to build JavaFX apps in Eclipse when I added the jfxrt.jar to the External Jars. But when trying to compile and run from the command line, it does not find JavaFX classes unless I specify the -cp option to javac and java. The server was originally using openjdk-1.6, but I used alternatives to configure javac and java to point to the newly installed JDK. It looks like that is working fine, except for this issue.
I found that the same problem plagued me when trying to run the JavaFX Exporter. I was trying to export a project that runs fine in Eclipse. But it could not find the JavaFX classes when trying to run. And I haven't worked out how to tell the exporter where the jfxrt.jar file is located.
For reference, the jfxrt.jar is located at /usr/java/jdk1.7.0_21/jre/lib/jfxtr.jar on my system.
when Oracle JDK7 is installed, it should not be necessary to specify the classpath to jfxrt.jar when the JDK is installed correctly.
That is not true.
If you want to compile and run a JavaFX application in Java 7 (u21) and you are not using the JavaFX packaging tools, you need to add jfxrt.jar to your classpath.
See Compile code using JavaFX 2.0 (using command line) for samples of setting the JavaFX classpath for compiling (with javac) and running (with java) a JavaFX 2 application from the command line.
Some IDEs or IDE extensions are aware of this and will automatically add jfxrt.jar to your classpath (e.g. the e(fx)clipse plugin or the NetBeans JavaFX project type).
Some 3rd party tools such as the JavaFX Maven Plugin or the JavaFX Gradle Plugin also package JavaFX applications so that you don't need to add jfxrt.jar to your classpath.
For Eclipse development, use of the e(fx)clipse plugin is recommended, as it takes care of classpath issues (as well as providing other useful capabilities for JavaFX developers).
For Java 8, jfxrt.jar is on the default classpath, so you don't need to explicitly set your classpath to use JavaFX with tools like javac.exe or java.exe for that Java version.
OpenJdk7 does not include jfxrt.jar. Use Oracle Jdk7 instead will help.

How to use groovy inside a Eclipse RCP project?

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.

Resources