Run oneJEE application with Java8 and another with Java 11 - java-8

I have two JEE applications, one runs under Java 8, the other runs under Java 11.
Is there a way to force each application to use the good Java version when I run it (via java -jar xxx.war)? Or do I need to update the Path environment system each time?
My issue is that Java 8 application cannot run with Java 11 because it generates the exception
java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
(which is not supported in Java 11).

you could do something like this :
export JAVA_LATEST=/usr/local/jdk1.8
export JAVA_OLD=/usr/local/jdk11
in $HOME/.bashrc
JAVA_HOME=$JAVA_OLD
in shell launcher of your JAVA 8 app
JAVA_HOME=$JAVA_LATEST
in shell launcher of your JAVA 11 app

Related

Sync error while trying to build project in IntelliJ

Getting the following sync error while trying to build my first helloWorld program in IntelliJ.
I've installed IntelliJ for the first time on my computer running Windows 10.
Could not open init generic class cache for initialization script 'C:\Users\nikhils\AppData\Local\Temp\wrapper_init5.gradle' (C:\Users\nikhils\.gradle\caches\6.6.1\scripts\2xaig2b083uxqwleg0fdntova).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 60
Change project and Gradle JDK to the supported version (8—15). Current Gradle release versions do not support Java 16. You would need Gradle 7 if you want to use Java 16.
The easiest way would be to create a new project with Java 11.
Also note that full Java 16 support will be available starting from IntelliJ IDEA 2021.1 release (current release version is 2020.3.3).
See https://www.jetbrains.com/idea/nextversion/ if you want to give it a try.

macOS: how to install JavaFX properly to run mqtt-spy?

I'm trying to run mqtt-spy-1.0.0.jar on my macOS 10.14 system but it won't start, returning the following error message:
According to the developers, this problem is caused if JavaFX is missing on the system.
The latest version of the Oracle JDK is installed on my system as can be seen below, however, I'm aware that Oracle has excluded JavaFX from the JDK in v11.
So I downloaded JavaFX from GluonHQ and followed their instructions on how to get started.
Despite having both required variables set correctly in ~/.bash_profile, mqtt-spy-1.0.0.jar is still returning the error message shown on the first screenshot ...
What else do I need to do or what do I need to do differently to run mqtt-spy?
There is already an issue filed about this, but not a solution.
I haven't really tried to get it fully working, but these are the required steps to run a jar on Java 11 that requires JavaFX 11, but doesn't bundle it:
Go to OpenJFX docs and read about how to get started with JavaFX 11.
Download JavaFX 11 for your platform from here. Unzip it
Providing that you have Java 11 installed, and set as JAVA_HOME:
With mqtt-spy-1.0.0.jar (as latest release), you can run:
java --module-path /path-to/javafx-sdk-11.0.1/lib \
--add-modules javafx.controls,javafx.fxml -jar mqtt-spy-1.0.0.jar
After you run this, you will get this exception:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
Since Java 9, JAXB is not part of the JDK either. So you can add try to download the dependency from here) and add it to the classpath. But this will take some iterations (there are a few other required jars more, see this).
So why don't you use the latest snapshot available, that includes dependencies: mqtt-spy-1.0.1-beta-b18-jar-with-dependencies.jar.
With this:
java --module-path /path-to/javafx-sdk-11.0.1/lib \
--add-modules javafx.controls,javafx.fxml -jar mqtt-spy-1.0.1-beta-b18-jar-with-dependencies.jar
I get:
Warning: But this doesn't mean that the app will fully work. Given that it is a Java 8 app, there are things that have changed in JavaFX 11, mainly related to the control skins. If the app was using private API (com.sun.javafx....), that won't work now, because either it has been moved to public packages, or because it is not accessible by the modules. For the latter you can use --add-opens, but for the former there is no solution other than update the app dependencies to Java 9+.

Unable to start Spring Boot executable jar using IBM JRE 1.8

We have a Spring Boot application which is built as an executable jar and runs fine using both the Oracle and OpenJDK JREs (using 1.8 versions).
Attempting to run it using the IBM 1.8 JRE however results in the following error at the command line.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
This occurs if we execute the jar (using ./application.jar) or using java -jar application.jar
This led us to change the packaging to not make the jar executable and this allows us to start the application using java -jar application.jar. So it appears the IBM JRE doesn't like the launch script.
The problem is we don't want to have two packaging methods for different deployment environments, if possible.
Does anyone have any experience of why the IBM JRE doesn't like the script on the front of the jar file and whether there are any command line options to disable whatever checking its doing?
From your post it is unclear if you have problem with
1) running jar from Linux like chmod a+x application.jar and executing
Or
2) running via /opt/IBM/java/jre/bin/java -jar application.jar
For option 1) it is not a good idea as you do not explicitly choose jvm binary and rely on OS to choose one for you.
Read about binfmt_misc mechanism:
https://en.m.wikipedia.org/wiki/Binfmt_misc
For option 2)-it might be class loading problem, please add
/opt/IBM/java/jre/bin/java -verbose:class -jar application.jar
and consult documentation here: https://www.ibm.com/developerworks/library/j-dclp1/index.html

SocketTimeoutException while opening New Spring Starter Project wizard on STS running with Java 7

I'm using the ZIP distribution of STS 3.5.1 for win32.
I start STS with this cmd script:
set JAVA_HOME=d:\jdk\jdk1.7.0_21
set PATH=%JAVA_HOME%\bin;%PATH%;
start .\sts-3.5.1.RELEASE\sts.exe
Then, when I do "New > Spring Starter Project", I get this error:
If I replace Java 7 with Java 6 by changing the first line of my cmd script, everything works fine: the wizard starts.
set JAVA_HOME=d:\jdk\jdk1.6.0_31
Is there something special to do if I want to use Java 7 ?
You probably want to get a more recent version of the JDK 1.7 (e.g. 1.7.0_51) as there were quite a few unpleasant bugs in earlier releases. Otherwise I don't have any suggestions. Can you see the service (http://start.spring.io) from your browser?

Java 7 Syntax error

I have Java 7 running on my mac:
System.out.println(System.getProperty("java.version")); // prints 1.7.0_05
Project was created using
Project properties confirm, i am on Java 7
Default system Java is 7
The following however results in syntax error
public static void main(String[] args) {
// Underscores in Numeric Litarals are ok here
int i = 11_234;
}
Eclipse is complaining with Syntax error on token "_234", delete this token
On Eclipse's Project|Properties dialog, there two entities Java Build Path and Java Compiler. The former will tell you what classes are used during the build, and you may have a Java 7 JRE listed there. The latter, however, is the compiler that will be used to compile your code. It is possible to have Eclipse use a Java 6 compiler even with a Java 7 JRE on the build path.
My guess is that you are using Helios, not Indigo. See Programming Java 7 in Eclipse
Make sure your version of Eclipse is 3.7.1 (this is Eclipse 3.7 Maintenance Build) or higher (see JDT/Eclipse Java 7 Support) and that you have registered Java 7 with Eclipse (see Eclipse and Java 7).

Resources