Heroku unable to detect java 11 - java

I am trying to deploy a java jar to heroku with heroku maven plugin.
I am using java 11 so I have added system.properties in the root folder(where pom.xml is present) and set java.runtime.version=11. However it doesn't seem to be working !
My plugin :
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<includeTarget>false</includeTarget>
<includes>
<include>${project.build.directory}/${project.build.finalName}.jar</include>
</includes>
<processTypes>
<web>java $JAVA_OPTS -jar ${project.build.directory}/${project.build.finalName}.jar</web>
</processTypes>
</configuration>
</plugin>
When I do git push heroku master it starts build process using jdk 8.
remote: Building source:
remote:
remote: -----> Java app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Installing Maven 3.6.2... done
remote: -----> Executing Maven
remote: $ mvn -DskipTests clean dependency:list install
Eventually build fails with error :
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project ImpactHub_bot: Fatal error compiling: invalid flag: --release ->
How do I set jdk verison to 11 ? I have also tried adding ${java.version} to configuration but it didn't help

That's exactly how you are specifying the Java version, see: https://devcenter.heroku.com/articles/java-support#specifying-a-java-version
You can specify a Java version by adding a file called
system.properties to your application.
Set a property java.runtime.version in the file:
java.runtime.version=11
I used it in my project as well and it is working.
Make sure your system.properties is saved as All Files. Furthermore it should be at the root folder of your git repo.
It might have a .txt ending. If that fails open a Support Ticket with Heroku.

Related

Heroku deploy build failure for Spring Boot REST API

I have a Spring Boot REST API locally.
It is successfully generating the .war file locally when I run mvn clean package.
Now I want to deploy it to Heroku.
These are the steps I've done.
Uploded the code to a github respository. Let's say \myrestapi.
Opened a terminal to run Heroku CLI commands
Logged in heroku
heroku login
Ran command to create the app on heroku
heroku create myrestapi
This command didn't work. Got the message saying the name "myrestapi" already existed.
So I changed the name to something else. Let's say "cl-myrestapi":
heroku create cl-myrestapi
It ran successfully.
Ran command to create the free postgreSQL database on heroku:
heroku addons:create heroku-postgresql:hobby-dev
Git push
git push heroku main
This starts downloads successfully.
But then generates the following error:
remote: [INFO] BUILD FAILURE
remote: [INFO] ------------------------------------------------------------------------
remote: [INFO] Total time: 14.653 s
remote: [INFO] Finished at: 2021-02-19T18:43:12Z
remote: [INFO] ------------------------------------------------------------------------
remote: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-
compile) on project myrestapi: Fatal error compiling: invalid target release: 11 -> [Help 1]
remote: [ERROR]
remote: [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
remote: [ERROR] Re-run Maven using the -X switch to enable full debug logging.
remote: [ERROR]
remote: [ERROR] For more information about the errors and possible solutions, please read the following artic
les:
remote: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
remote:
remote: ! ERROR: Failed to build app with Maven
remote: We're sorry this build is failing! If you can't find the issue in application code,
remote: please submit a ticket so we can help: https://help.heroku.com/
remote:
remote: ! Push rejected, failed to compile Java app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: e11a85238783f54ee30765ba4f8a55354930be
09
remote: !
remote: ! We have detected that you have triggered a build from source code with version e11a85238783f54ee30765ba4f
8a55354930be09
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to cl-myrestapi.
remote:
To https://git.heroku.com/cl-myrestapi.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/cl-myrestapi.git'
Why am I getting this error since it is building successfully locally?
There are only two differences I can see:
The need to have a different project name on heroku (see step 4 above)
Application.properties is different.
This is my original application.properties (that runs locally).
spring.datasource.url=jdbc:postgresql://localhost:5432/myrestapi
spring.datasource.username=xxx
spring.datasource.password=yyy
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
This is the updated application.properties (being uploaded to heroku)
spring.datasource.url=${JDBC_DATASOURCE_URL}
spring.jpa.hibernate.ddl-auto=update
UPATE:
Noted that when the git push heroku main command is executed, at the begining it says "Installing jdk 1.8", while I'm using version 11.
So that seems to be the issue.
To solve that I tried to add a System.properties file at the root with the following line:
java.runtime.version=11
But didn't solve.
First Don't forget to add this in pom.xml
<properties>
<java.version>11</java.version>
</properties>
Second, check project SDK and project language level (in project structure) both of them should be 11.
Check Java compiler in settings and make sure that project-byte-code-version
and target-byte-code-version have set 11.
Also for last chance if Heroku can't deploy, try this at bottom of your pom.xml file.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

Maven exec for Dropwizard project was not working

I tried to build a Dropwizard app and when i tried to execute it using mvn exec:java after including
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>${mainClass}</mainClass> //the application java class from properties tag
<arguments>
<argument>server</argument>
</arguments>
</configuration>
</plugin>
in command prompt when using the mvn command > mvn exec:java
expected it to build and deploy it, instead got the below issue
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) # hello-dropwizard ---
[WARNING]
java.lang.ArrayIndexOutOfBoundsException: 1
at org.hibernate.validator.internal.util.Version.getJavaRelease(Version.java:36)
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:120)
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:106)
at org.hibernate.validator.HibernateValidator.createSpecializedConfiguration(HibernateValidator.java:27)
at org.hibernate.validator.HibernateValidator.createSpecializedConfiguration(HibernateValidator.java:24)
at javax.validation.Validation$ProviderSpecificBootstrapImpl.configure(Validation.java:220)
at io.dropwizard.validation.BaseValidator.newConfiguration(BaseValidator.java:28)
at io.dropwizard.jersey.validation.Validators.newConfiguration(Validators.java:35)
at io.dropwizard.jersey.validation.Validators.newValidatorFactory(Validators.java:27)
at io.dropwizard.setup.Bootstrap.<init>(Bootstrap.java:68)
at io.dropwizard.Application.run(Application.java:72)
at com.dropwizard.demo.HeloDropWizardApplication.main
Is there any reason for this behaviour?
Noticed that i had java 9 installed in the system, with little research on the hibernate validator class, it expects 8 to be returned since i had 9 the version was not returned in a specific way as the below code
String[] specificationVersion = System.getProperty( "java.specification.version" ).split( "\\." );
return Integer.parseInt( specificationVersion[1] );
I have changed the PATH to include the java 1.8 path even then maven threw same exception.
I have to use > mvn package
then use > java -jar target\dropwizarddemo.jar server

Maven build error after setting toolchain right

I have Java version 1.8.111 installed and the initial error message after running mvn3 install was as below.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-toolchains-plugin:1.1:toolchain (default) on project myfile: Cannot find matching toolchain definitions for the following toolchain types:
[ERROR] jdk [ vendor='sun' version='1.6' ]
[ERROR] Please make sure you define the required toolchains in your ~/.m2/toolchains.xml file.
To resolved this, I've updated my toolchains.xml to version 1.8.111 but still getting the same error. I've also tried after running mvn3 clean and successfully cleaned but still getting the same error.
Could anyone pinpoint where this version 1.6 is fetched from?
I checked JAVA_HOME already, it's set to 1.8.
Can anyone explain how maven calls Java version?
Appreciate your help.
Below is my toolchains.xml
Your application is expected to be built with JDK 1.6 and to locate it Maven is looking for definition of [ vendor='sun' version='1.6' ] within toolchains.xml in your {home}/.m2/ directory (see eg this maven guide). You just need to point to it and all should be good.
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>1.6</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/Library/Java/JavaVirtualMachines/jdk1.6.X_XX.jdk/Contents/Home</jdkHome>
</configuration>
</toolchain>
</toolchains>

Compilation error Multiple version of JAVA

I am having the below issue when I run my maven build in eclipse. I saw many posts like this but i still can't solve this problem .Mine may be a little more specific, I know that my JAVA_HOME is pointed to java6, and that is because I am working on another application which uses java 6. The application in which I am running into issues uses Java 8
[ERROR] COMPILATION ERROR : [INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in: C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required). .In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable. [INFO] 1 error
<br>[INFO] -------------------------------------------------------------
<br>[INFO] ------------------------------------------------------------------------
<br>[INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------
<br>[INFO] Total time: 11:53 min [INFO] Finished at: 2016-08-18T16:52:13+05:30
<br>[INFO] Final Memory: 11M/141M
<br>[INFO] ------------------------------------------------------------------------
<br>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project
Compilation failure [ERROR] Unable to locate the Javac Compiler in: [ERROR] C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and [ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
<br>[ERROR] In most cases you can change the location of your Java [ERROR] installation by setting the JAVA_HOME environment variable.
[ERROR] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
How can I resolve this problem without installing java 8 as it may may make changes to my JAVA_HOME etc which would make my other application to not run. Is there a way to get the JDK folder without running the .exe (p.s I already tried the 7zip method)
Please suggest
If you have the jdk8 then you can open cmd, run the command in this window to modify the JAVA_HOME set JAVA_HOME=<jdk8 path>. This will modify the JAVA_HOME env variable only for this instance of the cmd session and not for the whole OS. Now run the maven build command from this window and it wont fail.
If you wanna run the build from eclipse, then in eclipse try going to Windows --> Preferences --> Java --> Installed JREs --> click Add button --> Sel Standard VM and click next --> put in values for 'JRE Home' as path till the jdk folder and 'JRE Name' as java8 or whatever you wish --> click Finish.
Now right click the project of you interest --> click properties --> Java Compiler --> Tick 'Enable project specific settings' --> and select 1.8 here.
If 1.8 is not visible here, go to Java Build Path --> Add Library --> JRE System Library --> Alternate JRE --> select jdk8 --> Finish
Looking at the path in that error (C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar) you've installed the Java Runtime Environment (JRE).
To compile java you need the Java Development Kit (JDK) which contains the tools the maven plugin needs.
You can change your maven-compiler-plugin configurations to your JAVA_HOME.
Just go to eclipse window->preferences->type maven->and you could see something like template click on that and look for javac compiler, just go there and change to whatever java version you have.
<configuration>
<!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
<source>${cursor}1.6</source>
<target>1.6</target>
</configuration>
Without java8 and without .exe file you can't go ahead with your requirement.
Hope it's useful.
from your error log it says that
[ERROR] Unable to locate the Javac Compiler in: [ERROR] C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar
paste this code in your pom.xml inside build tag and make sure you add dependencies properly and please change your java version accordingly
this will only work if you have something wrong in your pom.xml.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_HOME}/bin/javac</executable>
<compilerVersion>1.8</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<jvm>${JAVA_HOME}/bin/java</jvm>
<forkMode>once</forkMode>
</configuration>
</plugin>
</plugins>
note your JAVA_HOME must point like this
C:\Program Files\Java\jdk1.8.0_65
edit
There must be various reasons like
your pom is not getting path to java home
your java home is not set
you are using jre instead of jdk in your IDE
You can download the version of the JDK without installer.
Then specify a JDK 1.8 as source and target in the compiler configuration of the pom.xml with which you have your problem. in this way you don't need changing your JAVA_HOME :
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerVersion>1.8</compilerVersion>
<fork>true</fork>
<executable>D:\jdk1.8\bin\javac</executable>
</configuration>
</plugin>
<build>
I followed steps in the below link to get the portable JDK:
http://bgasparotto.com/convert-jdk-exe-zip/

Maven GAE Plugin - Unable to run gae:debug

I'm having trouble running the gae:debug goal of the Maven GAE Plugin. The error I'm receiving is below. Any ideas?
I'm running it with "mvn gae:debug".
[INFO] Packaging webapp
[INFO] Assembling webapp[test-gae] in [C:\development\test-gae\target\test-gae-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in[56 msecs]
[INFO] Building war: C:\development\test-gae\target\test-gae-0.0.1-SNAPSHOT.war
[INFO] [statemgmt:end-fork]
[INFO] Ending forked execution [fork id: -2101914270]
[INFO] [gae:debug]
Usage: <dev-appserver> [options] <war directory>
Options:
--help, -h Show this help message and exit.
--server=SERVER The server to use to determine the latest
-s SERVER SDK version.
--address=ADDRESS The address of the interface on the local machine
-a ADDRESS to bind to (or 0.0.0.0 for all interfaces).
--port=PORT The port number to bind to on the local machine.
-p PORT
--sdk_root=root Overrides where the SDK is located.
--disable_update_check Disable the check for newer SDK versions.
EDIT: gae:run with the jvmFlags option is also giving me the same result with the below configuration.
<plugin>
<groupId>net.kindleit</groupId>
<artifactId>maven-gae-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<jvmFlags>
<jvmFlag>-Xdebug</jvmFlag>
<jvmFlag>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000</jvmFlag>
</jvmFlags>
</configuration>
</plugin>
It looks like this is an open issue. I have submitted a patch for this (see Issue 38).

Categories