No compiler is provided in this environment. maven build failed - java

I am getting the following error while using the following command
mvn clean install package
Error
No compiler is provided in this environment. Perhaps you are running
on a JRE rather than a JDK?
I have tried the solutions already present online but none of them worked, I have my JDK path selected in the installed JRE's on my eclipse.
I am using Ubuntu 16.04. Can someone help?
I have already tried the solution given in No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
but that didn't help. I already have my JDK path selected correctly

Check JAVA_HOME path is set as the environment variable pointing to JDK. Refer maven installation steps for more information.
https://maven.apache.org/install.html

Give the jdk path in /etc/environment
Eg : JAVA_HOME="/usr/lib/jvm/java-8-oracle"
then
source /etc/environment
also add in bashrc
vi ~/.bashrc
export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64"
source ~/.bashrc

I had this same exact error.
There are a lot of possible solutions posted for this problem, even more duplicates. However, after checking many of them I did not find the solution. After some tries and investigations among my environment settings I have found out that the issue was caused by having multiple java paths pointing to different versions that were set up by different IDE's. Also, it seems that Maven was trying to use the first version it found in the PATH settings which actually appeared to be a JRE version.
The solution for me was to put the path pointing to Java JDK as the first path in the PATH environment settings.
Also, make sure that the new environment settings are in effect before you try to use Maven again.
A very simple way to see if mvn actually tries to use the JDK is to execute the following command:
mvn -version
It will print out the Java paths along with other info.

Related

Gradle problems with Java JRE/JDK and JAVA_HOME or java.home

Windows 10 OS. I'm using a Cygwin BASH console to run Gradle.
I've been struggling with this for a few hours now. There are one or two questions on SO which seem to relate this but I'm still a long way from understanding the basic mechanisms and how to get Gradle to use the right JDK/JRE.
This started earlier when gradle build didn't work and complained that it couldn't find "tools.jar". This appears to be a sign that the path to the Java JRE used to run the Gradle app isn't associated with a JDK. This is indeed the case: the JRE it insists on using to start up is at "C:\Program Files\Java\jre1.8.0_73\". This is a JRE without a JDK.
The JDK I want Gradle to use is at "D:\apps\Java\jdk1.8.0_191\".
I have set JAVA_HOME to this value. I have also placed "D:\apps\Java\jdk1.8.0_191\bin\" at the very start of the PATH environment variable.
In both Cygwin and the W10 console, when I go "java -version" it prints out the 1.8.0_191 version, proving that the OS System is configured as expected.
But Gradle itself insists on using the JRE in C:.
I tried numerous experiments and rebooted numerous times.
When I went, in build.gradle:
println "java.home is ${System.properties['java.home']}"
... it always printed out the C:\ location version (1.8.0_73)
Finally I made this impossible by renaming "C:\Program Files\Java\" to "C:\Program Files\JavaXXX\". This then gives:
Chris#M15B /cygdrive/d/My Documents/software projects/EclipseWorkspace/LuceneIndexer_3
$ gradle build Error: could not open `C:\Program Files\Java\jre1.8.0_73\lib\amd64\jvm.cfg'
So it appeared, as far as I could surmise, that something inside Gradle has got its heart stubbornly set on using a particular JRE location... which disregards the JAVA_HOME variable, the PATH entries and the OS's own understanding of which JDK/JRE should be used... and even sets System setting java.home to a "spurious" setting (or one I don't want to use).
Finally... I put this line in gradle.properties:
org.gradle.java.home=D:\\apps\\Java\\jdk1.8.0_191
When I then changed "C:\Program Files\JavaXXX\" back to "C:\Program Files\Java\", finally the thing built properly. And finally java.home was printed out as "D:\apps\Java\jdk1.8.0_191". But when I again renamed to "C:\Program Files\JavaXXX\" the "could not open" error returned. In other words, even if you can configure java.home in Gradle, Gradle itself appears to be reliant on a version of Java that you don't want it to use, and which is not the version for which the OS is configured!
How on earth does the Gradle application find the JRE it is going to use to do its business? Surely there must be a way to get it to use another one?
later
I also tried adding some ECHO statements to the gradle startup script... in which there is a specific section devoted to determining the JVM to use. These experiments showed clearly that this script is correctly using the desired JDK (under D:). Nor can it be a Cygwin-related problem, as other Cygwin commands work fine when Java\ is renamed to Java_XXX. I also examined the registry: no clues found.
By going "gradle" at the Cygwin command prompt, something somewhere in the works insists on using a baked-in JRE location, even before the gradle startup script is run...
I was able to resolve this by upgrading my system's Java and Gradle. I changed to Java 9 (although apparently we're on Java 11 at the time of writing). I also changed to Gradle 5.2.1 (from 3.5). I think I concluded that Gradle 3.5 was incompatible with Java 9...
I was quite confused: for a moment it appeared that Cygwin was out of date and that I needed a newer version of its Gradle. But in fact Cygwin was inheriting PATH from W10, and one of those PATH entries was "%GRADLE_HOME%\bin". Cygwin was using the W10 Gradle. What fun to be using a Windoze OS!
GRADLE_HOME (different from GRADLE_USER_HOME, where dependencies are downloaded!) thus had to be changed to the location of the new version of Gradle.
All sorts of funny consequences followed for Eclipse: the dreaded red exclamation marks... caused by the fact that under "Project and External Dependencies" for several projects the dependencies revealed themselves to be located in the old 3.5 GRADLE_USER_HOME location, which I had renamed deliberately to make it inaccessible. I found no way to "rebuild" these dependencies in Eclipse (i.e. to force use of GRADLE_USER_HOME, now pointing to a location under ...5.2.1), and instead opted to recreate the Eclipse projects.
Quite trying. There must of course be a better way.
Incidentally, it does indeed appear that when you run a Gradle command in Cygwin the JVM as configured for your OS in the "Java Control Panel" gets invoked before the gradle startup script is run (... I think). Even if your JAVA_HOME setting and first PATH entry are pointing to a different JRE (which they probably shouldn't be).

Jenkins / Maven: Could not resolve default JAVA_HOME path, Build failing

I've got a problem regarding Java Builds in Jenkins.
The Error I resolve is the following one:
Unable to locate the Javac Compiler in:
C:\Jenkins\jre\..\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.
I got JDK1.6 and JDK1.7 projects, so I need two JDK installations. For my default Java JDK I used the 1.6 for the JAVA_HOME variable, which points to C:\Program Files\Java\jdk1.6.0_45. Same for the 1.7 version, but in a separated variable (JAVA_HOME7).
The PATH variable contains the appended \bin to the two JDK versions.
In Jenkins I also added both versions for JDK and as helper variables.
If I am setting a concrete version for a project (e.g. JDK1.7), then it's building without any issues. Unfortunately I've got a lot of build-projects, so it would be time consuming to set this manually.
I don't understand where the call or variable for the path of the error C:\Jenkins\jre\..\lib\tools.jar is set and where I can modify it...
Jenkins Version: 1.509.4
Any hints or advices how to solve this problem?
I faced the same problem. The below steps solved the problem
1) Go to Manage Jenkins - Configure system
2) Add JAVA_HOME and its path in Global Properties - Environment Variables
3) Add JDK and path in JDK section

system cannot get java compiler please use jdk intead of jre

When trying to deploy my application to the Google App Engine server I get the following error:
Cannot get the System Java Compiler. Please use a JDK, not a JRE.
All solutions I've seen for this involve editing an eclipse configuration file, but I'm not using eclipse. I'm executing appcfg.cmd from the dos prompt.
I have a jdk installed and my JAVA_HOME is pointing to it:
c:\program files\java\jdk1.7.0_45
Few points:
Could you check if the JAVA_HOME\bin folder is in the PATH environment variable. If not put that and make sure that it is pointing to the correct version.
Also check java -version on your machine after setting it.
I think you need to add the bin folder as the sub-directory please give it a try
c:\program files\java\jdk1.7.0_45\bin

Java Compilation error Not able to configure JAVA_HOME

When i am running Jenkins which checks out code from a repository and perform mvn package or some command. I get this error:
Unable to locate the Javac Compiler in: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../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.
My JAVA_HOME points at jdk location only.Still it looks at
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/tools.jar
for the compiler.Why is that???
It seems the problem is with the code ..It points to /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/ for the tools.jar,whereas it needs to look into the /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/lib/ where the jar is present.I tried copying the jar to jre /lib/ but to no avail.Any solutions for this...
Thanks for d answers anyway..
You need jdk (java development kit) to compile java programs. jre only use to run compiled java programs. in your case its point to a jre and thats why you are getting this.
you can download the jdk and install.
you can download jdk rpm from here
http://www.oracle.com/technetwork/java/javase/downloads/jdk7u9-downloads-1859576.html
use this to choose java alternative if you have already installed.
/usr/sbin/alternatives --config java
Uninstall the installed JRE. Keep only one JAVA defined by JAVA_HOME and define your lib and classpath with respect to JAVA_HOME.

Running J2EE Eclipse in a VM - Unable to find a javac compiler

Kinda new posting up questions here so bear with me. I had to install a XP VM recently in order to run a program that required use of an Oracle 10g client. I setup my tomcat server and when I went through the directory and started the .jsp file, I got this error
2011-02-22 09:13:01,291 ERROR (org.apache.jasper.compiler.Compiler:394) - Javac exception
Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
Weird thing is I set my JAVA_HOME variable in my VM to 'C:\Program Files\Java\jdk1.6.0_24;' and my PATH variable to '%JAVA_HOME%\bin;'.
It says that its a jasper-complier error... I made sure to add several TOMCAT_HOME variables in my eclipse library path that looked at the jasper-compiler,jasper-runtime,jsp-api.jar, and servlet-api.jar located in my tomcat server folder.
I also followed these instructions here, that state to add the jdk\bin's tools.jar to Eclipse's Ant runtime global entries
Any help appreciated, I'm stumped.
It usually happens because Oracle ships with an outdated version of JDK which conflicts the PATH that we set. Scan your PATH environment variable for any oracle JDK and remove it. It should help.
Look into your Launcher configurations (of type 'Apache Tomcat') and find the one created when you launched the JSP. There must be an 'environment tab'. You could define the JAVA_HOME here. Is this a version 5 of Tomcat (or earlier) ? Starting with version 5.5, Jasper has an embedded JDT (eclipse java compiler).
Hey I figured it out, just made sure you add to your JDK to your PATH variable (ie. java\jdk...\bin) and I also added it to my tomcat\lib folder and added it to my projects library as another variable.

Categories

Resources