wrong java version in heroku - spring-boot

I've created a spring boot app and would like to run it on heroku.
My app is compiled using java 9.
As I'm deploying it to heroku using the CLI plugin I'm getting
Exception in thread "main" java.lang.UnsupportedClassVersionError: io/safeblocks/firewall/FirewallApplication has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Clearly this means java versions mismatch. I added the system.properties file to my resources folder with the property java.runtime.version=9 as explained but still getting the same error.
As I run the command heroku run java -version --app myApp I'm getting:
openjdk version "1.8.0_171-heroku"
OpenJDK Runtime Environment (build 1.8.0_171-heroku-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
So it seems heroku is still not picking up the required java version.
Any ideas?

I see you added the system.properties file to your resources folder, I did the same mistake. The file system.properties must be placed under the root folder of your project.
The content of your file is correct:
java.runtime.version=9
After you moved the file to the root folder, commit your changes and do:
git push heroku master
Everything should be fine then.

Related

Jhipster project - error with ConfigurationMetadataAnnotationProcessor class in spring-boot app

I just start a new Jhipster project on my computer.
I have install the Open JDK 11.0.6, the last version on node and npm (node 16.15.0).
I have created the project with jhipster to test it but I have some issues to launch the backend part with spring-boot in Intellij.
When I open my project in IntelliJ and launch the Spring boot app, I got this error:
java: Supported source version 'RELEASE_6' from annotation processor 'org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor' less than -source '11'
This error comes during the compilation of the application
I put below some screen of my configuration
My java version in cmd
My java in PATH variable
Java set in project INTELLIJ as SDK
Java for the module
And to finish, before all this, a java 1.6 was install on the computer but I have cut all the way to call it (PATH & JAVA_HOME). I can't delete it totally because I'm not an administrator of my computer.
Thanks for the idea in advance,
Have a good day,

How to resolve compileJava errors during heroku deployment?

I worked as follows to deploy Intellij Spring Boot using gradle on heroku. I proceeded from the directory containing the source files.
> git init
> git add .
> git commit -m "first commit"
> heroku create
> git push heroku master
However, the following error occurred during the push process.
What went wrong: Execution failed for task ':compileJava'.
invalid source release: 11
After the problem occurred, a file called system.properties was also created in the source file and the following input was also entered.
java.runtime.version=11
But it is still unresolved. How do I solve this problem?
First you have to ensure your local development and your deployed instance are using the same version.
You specified a version with system.properties with content java.runtime.version=11 but haven't provided an image of the updated log. The log still says you are installing JDK 1.8.
Furthermore you should specify a Java version that is currently being supported. You can find the versions here: https://devcenter.heroku.com/articles/java-support#supported-java-versions
Java 7 - 1.7.0_302
Java 8 - 1.8.0_292
Java 11 - 11.0.11
Java 13 - 13.0.7
Java 15 - 15.0.3
Java 16 - 16.0.1
I've just face this problem following a course. Solve it by change the sourceCompatibility='17'(on my file) to '1.8' on my built.gradle file change sourceCompatibility='1.8' on build.gradle file
and change the Gradle JMV on setting and JKD on project structure to 1.8.
enter image description here
duno if the last change anything, but worked for me.

Application has been compiled by a more recent version of the Java Runtime (class file version 55.0), this versions up to 52.0

I am trying to run the docker image in AWS cloud so in the local ,compiled the application with jdk-11.0.1 and written docker file like this;
Please note that I have not installed any JDK in AWS ec2 instance because I have already included adoptopenjdk/openjdk11:latest image in the final image..
FROM adoptopenjdk/openjdk11:latest
ADD target/demo-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
EXPOSE 8080
1)create the docker image
2)pushed the docker image to docker hub
3)when I run the docker container then getting below error.
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/example/demo/DemoApplication has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Most probably java got updated in local so you are compiling with a different version than you think. Or the local version is different than "adoptopenjdk/openjdk11:latest".
I suggest you use a multi-stage build so that your classes are always compiled against the same java version.
How you write your build stage depends on your environment so I don't have enough information to post an example. But basically you need to replicated everything you do in local inside the build stage. Then you just copy the jar to the last stage. And this will always work.
Try changing your openjdk version to latest i.e FROM:openjdk:12 work for me as i am using latest java version, use respective openjdk versions to match at runtime
To avoid this kind of issue It is recommend to be very specific about the images.
i.e. FROM adoptopenjdk/openjdk11:jre-11.0.9.1_1-alpine
For this kind of best practices I would suggest to go through this article I found while looking for the solution.

SonarQube startup Error: log4j2 could not find a logging implementation. Please add log4j2 to the filepath

I resolved this issue, I did it by following the instructions found here:
Elasticsearch installation : Error missing 'server' JVM at ...jvm.dll
I was using SonarQube fine the day before, but today when I tried to start the program I'm getting a error.
I have not changed anything on SonarQube as far as I know, I did made a successful connection with SonarQube to Jenkins. But if I remember correctly, I didn't had to install/change files for SonarQube for this(I just made a project, and generated a user login token for Jenkins). Also, I'm sure I'm using the "vanilla" version of SonarQube.
Download and install Java
Go to
c:/program files/java/jre/bin
and create a folder called "server"
Now go into the
c:/program files/java/jre/bin/client
and copy all data of this folder to
c:/program files/java/jre/bin/Server
updating/reinstalling the target jre (jre-8u181-windows-x64 for sonarqube 6.7.x) resolved this for me
I copied these jar in this route and it worked:
path: sonarqube-6.7/lib
log4j-api
log4j-core
This is a side effect; your have a JRE in your Windows PATH.
You need a JDK in your %PATH% // see previous error log
jvm 1 | Error: missing `server' JVM at `C:\Program Files (x86)\Java\jre1.8.0_191\bin\server\jvm.dll'.
jvm 1 | Please install or use the JRE or JDK that contains these missing components.
Used JDK 15, had same issue
Installed OpenJDK 11 instead (https://jdk.java.net/java-se-ri/11)
opened "[path to sonarqube folder]\conf\wrapper.conf"
replaced "wrapper.java.command=java"
with "wrapper.java.command=C:\Program Files\Java\jdk-11\bin\java.exe"
worked for me.

Unable to execute a JavaFX application bundled without JRE

I'm having some troubles trying to deploy a JavaFX application. In order to simplify my problem I've tried to do the same with a "Hello word" application and the problem is the same.
I'm currently using IntelliJ IDEA and Gradle.
My build.gradle file is this:
apply plugin: 'java'
apply from: "http://dl.bintray.com/content/shemnon/javafx-gradle/8.1.1/javafx.plugin"
repositories {
mavenCentral()
}
javafx {
mainClass 'Main'
}
That build.gradle file works. The problem is that it embeds the JRE into the bundle so the file size is about 175 MB. That's too much for a simple "Hello World" app, don't you think?
So, I want to bundle this simple app without the JRE (yes, I know that I should distribute my app with the JRE bundled so it doesn't relay on uses system but I'm going to distribute both versions: with and without JRE bundled). In order to do this I add a single line to the build.gradle file (as explained in this link:
...
javafx {
mainClass 'Main'
javaRuntime '<NO RUNTIME>'
}
But no bundles are generated when gradle jfxDeploy. In fact, running gradle jfxDeploy -i show some interesting info:
Java runtime to be bundled: none, bundle will rely on locally installed runtimes
...
Skipping Mac Application Image because of configuration error The file for the Runtime/JRE directory does not exist.
Advice to Fix: Point the runtime parameter to a directory that containes the JRE.
Skipping DMG Installer because of configuration error The file for the Runtime/JRE directory does not exist.
Advice to Fix: Point the runtime parameter to a directory that containes the JRE.
Skipping PKG Installer because of configuration error The file for the Runtime/JRE directory does not exist.
Advice to Fix: Point the runtime parameter to a directory that containes the JRE.
Skipping Mac App Store Ready Bundler because of configuration error The file for the Runtime/JRE directory does not exist.
Advice to Fix: Point the runtime parameter to a directory that containes the JRE.
Ok, so maybe the plugin has some bugs. I try to generate the bundle with javapackager. I go to project folder and run the following:
javapackager -deploy -native image -srcfiles build/libs/ -outdir build/distributions -outfile Sample -appclass Main
The output is OK. The bundle is correctly generated with the JRE embedded. Now I try to generate a bundle without the JRE with this:
javapackager -deploy -native image -srcfiles build/libs/ -outdir build/distributions -outfile Sample -appclass Main -Bruntime=
(It's the same command appending -Bruntime= as explained in this link).
The bundle is generated. Now its size is about 500 KB. But when I try to run it nothing happens. Running it in a terminal gives the following (simplified) output:
$ Main.app/Contents/MacOS/Main
Failed to find library.:
Main:Failed to locate JNI_CreateJavaVM
Main:Failed to launch JVM
It seems that the bundle is not capable to start the local JVM. The jar is correctly generated and added to the bundle. Running it with java -jar runs the app but I don't know why it doesn't work when running the bundle
FYI, I'm running java 1.8.0_74, javac 1.8.0_74 and javapackager 8.0 in an OS X 10.11.2
The javafx.plugin from shemnon isn't developed nor maintained anymore, for that reason I've created the javafx-gradle-plugin.
The problem comes with the internal changes of the .cfg-file-format, they use INI-files now, but that is flawed in term of RUNTIME-configuration.
Official JDK-bug-tickets reported by me:
(jdk 9) https://bugs.openjdk.java.net/browse/JDK-8143314
(jdk 8) https://bugs.openjdk.java.net/browse/JDK-8143934
It should be enough to set some bundler-argument launcher-cfg-format to cfg within your build (or use the javafx-gradle-plugin, which includes that workaround automatically).
Disclaimer: I'm the maintainer of the javafx-maven-plugin and the creator and maintainer of the javafx-gradle-plugin.
UPDATE this got fixed and made available with JDK 8u92

Resources