Changing JVM version used by Groovy builds in Drone.io - java

I am working on a Java test project using Cassandra for persistence and Achilles as my client API for Cassandra. Also, for testing purposes I am running Gradle builds on this project in Drone.io.
The Achilles library depends on Java 7, which is one of the possible types of builds for Drone.io, but since this is a Gradle build, it is necessary to make it a Groovy build. According to this official doc page, it should still be possible to use Java 7 inside the Groovy JVM with just an additional command in the build script in order to change from the default 1.6 JVM:
sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
However, after adding that line to the build instructions, I get the following error messages from the Drone.io build log:
update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so
This is apparently a frequent error for which I managed to Google a number of solutions.
My problem is that all of these solutions involve installing plugins and/or adding entries to the sources list, which doesn't seem to be very straightforward in the Drone.io virtual machine.
One solution was running sudo update-alternatives --install /usr/lib/mozilla/plugins/mozilla-javaplugin.so mozilla-javaplugin.so /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/libnpjp2.so 1 (I updated the path from the original solution in order to reflect the VM's directory structure) to install the missing lib, but there is no libnpjp2.so file at this location in the VM.
Has anyone had better luck using Java 7 in Groovy/Gradle builds in Drone.io or has any idea of a workaround?

The best way to use Gradle with drone.io (and even in general) is via the Gradle Wrapper. This works with any drone.io build type, so you can simply select Java 7.

Related

Can't integrate SWT with JavaFX under "Zulu" JDK 11

We want to use both SWT and JavaFX in an Eclipse plugin within our RCP application. Unfortunately, we're experiencing problems integrating SWT with JavaFX under Java 11. The build environment uses e(fx)clipse 3.5. We're developing against the Community edition of Azul Systems' "Zulu" JDK 11, bundled with Azul's version of OpenJFX.
Formerly, we developed under Java 8. At that point, our build used a compile-time class path referring to jfxswt.jar, which lived in the jre/lib directory of the JDK. We didn't use any special class path settings at run-time.
We are now trying to move to Java 11. There, this JAR has become javafx-swt.jar and lives in the lib directory of the JDK. It no longer seems to be enough to set the class path to refer to this JAR at compile time: it seems to be necessary to do so at run time too. If we don't do this, we get an error (java.lang.NoClassDefFoundError: javafx/embed/swt/FXCanvas).
As a test, we experimentally embedded javafx-swt.jar within the JAR implementing our Eclipse plugin. We then referred to it in that plugin's .classpath file, and the code worked as expected. Unfortunately, we can't embed the JAR this way for legal and other reasons.
A note on Java modules: javafx.swt does not show up in the output when we issue the --list-module command. We tried running the application using parameters -p /path/to/JDK/lib/javafx-swt.jar --add-modules javafx.swt, but this doesn't seem to solve the problem.
My question: Is there a way to set up the class or module path to allow our Eclipse plugin to find this library in the JRE? Any solution would have to work with whatever JRE the code happens to be run against (I think it is all right to assume lib/javafx-swt.jar will live in that JRE).
Would it help to use a separately-downloaded version of OpenJFX rather than the copy of OpenJFX in our JDK?
Very many thanks ☺

How to use openjdk-8-native as default java in yocto build?

Within one of my application logic recipes, I need to use java during compilation time on the host system. The tool needs java 1.8 and fails to work with the jamvm-native and cacao-native packages.
What I have tried so far is to add the meta-java layer to my configuration and add DEPENDS = openjdk-8-native to my application logic recipe. This makes yocto compile the openjdk-8-native just fine.
Then, when I start a devshell for my own recipe java -version gives me
java version "1.5.0"
JamVM version 2.0.0
I can find the correct java from openjdk-8-native within the recipe-sysroot-native/usr/lib/jvm/openjdk-8-native/bin/ directory, but how can I make it the default java in PATH or use update-alternatives to make my build tool pick it up correctly?
Just for clarification: I do not need java on the target, just a native build during build time of another tool. I'm currently using yocto rocko version.

using wildcards for projectCP in evosuite test case generation

I use evosuite 1.0.1 for automated test case generation for several open source projects. I use java 1.8 on a unix platform (ubuntu 14.04).
Is there a way to use wildcards for dependencies in the -projectCP tag?
Some of my projects depend on a huge number of libraries and this could save me heaps of time. If you have a solution for either terminal or ant build script (no IDE) I would be very thankful!
It is (currently) not possible to use wildcards in -projectCP. A workaround is to use first the -setup option to create the classpath (in which using wildcards is possible) on a configuration file on disk, and then run EvoSuite without -projectCP (as the CP will be taken by the previously generated file). For more info, look at the documentation on http://www.evosuite.org/documentation/commandline/

Maven: compile Java 7 with JDK8

I need to ensure one thing before doing it, so I have not yet tested the solution I'll propose.
I have a Jenkins on which one project compiles with a JDK 7 with target Java 7. I have a new project written in Java 8, and I'd like to add it to my Jenkinsfor it to build it too.
As a consequence, I need to install a JDK 8 on the machine. I know we can specify the java compiler version in the pom of each project, but I'm fearing this: once I have installed JDK 8, will my Java 7 project still be able to compile with that JDK 8? Should I have the two JDK installed on the machine, and have a configuration for each project to be able to locate its own JDK? Or will my Java 7 project be able to compile in Java 7 using the JDK 8 ?
Thanks for any help.
As stated in comments, it is possible to install multiple JDKs on Jenkins machine (see this answer as an example) and to configure each job to use a specific one.
Besides, you could perfectly compile your Java7 project using Java8 JDK. However, I advise you not to do that. indeed, if backwards compatibility is enforced at language level, you may find some APIs in which bugs you were unaware of, but the libs you use already knew, have been fixed, creating some weird behaviours. As a consequence, your Java7 application would compile using Java8 JDK, but expose bugs at runtime. And it would be the hell of a nightmare to solve those bugs (believe me, my friend, I've met that kind of horrors in a previous common company).
You can use multiple jdk on your machine, but remember to use specific jdk for specific project. Configure POM file of your project carefully if you have installed multiple jdk. Compiling Source Using Maven
Or you can change JAVA_HOME in the Build Environment section of the job configuration you can set environment variables for the job. Although, you can use multiple JDKs but its not a good practice to in CI/CD. Use specific machines with specific configurations.

Executing Eclipse plugin (jdt/ast) outside eclipse IDE environment

Can I execute Eclipse Java development tools as a standalone process? I need to get Java program's AST structure using Eclipse JDT from another program, and to do that, I need to execute eclipse plugin as a stand-alone process behind the scene.
Is that possible? If so, how one can do that?
Eclipse/jdt and eclipse/ast is nothing more than a jar file, so one can use them to build standalone java application.
Example
I googled to find ASTExplorer as an example to make eclipse/ast plugin as a standalone java project.
The program was targeted for pretty old eclipse (3.0.2), I downloaded the 3.0.2 for Mac OS X this site - http://archive.eclipse.org/eclipse/downloads/drops/R-3.0.2-200503110845/
You need to setup ECLIPSE_HOME classpath variables in Preference -> Java -> Classpath variables
The .classpath has those classpath variables already, you can refer to this post - .classpath contents update in eclipse. As you can see it refers eclipse/jdt(art) jar files. I'm pretty sure one can change the reference to the newest version of jdt/ast without downloading the 3.0.2 version.
As I use Mac, I need to replace the swt for PC with swt for Mac. I could do that in BuildPath/Configure Build path
First remove the PC swt reference.
Then add the correct Mac swt reference.
Compile the example with the eclipse indigo/on mac
When the setup is correct, eclipse starts building the project. You can use Project -> Build Project menu. Then, you can check the application works fine in eclipse.
Generate the executable jar
Export to executable jar file.
You'll get some warnings, but you'll have a jar file.
Execute the generated jar
Just executing java -jar ast.jar doesn't work on Mac, I got a hint from this post.
Running SWT based, cross-platform jar properly on a Mac
In short, you need to run java -XstartOnFirstThread -jar ast.jar
Does it have to be Eclipses's AST? Or is any AST generation o.k.? If it doesn't have to be eclipse, I'd suggest Habelitz open source Java AST Compiler. http://www.habelitz.com/ I'm using it myself for some projects....
Well, of course you can launch eclipse just like any other process : How to create a process in Java
And then the problem becomes relaying the information back to the original process, which gets kind of messy. My suggested approach in this case would probably be to create a plugin in eclipse and have that plugin do whatever it is you think you need the AST for. You can work out messages with command line options to eclipse, or a shared file or something.

Categories

Resources