Gradlew unable to find a javac compiler - java

So I am trying to create a Workspace for eclipse from gradlew. And I am getting the following error:
Execution failed for task ':makeStart'.
> 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.
It is currently set to "C:\Program Files\Java\jre1.8.0_131"
But I`ve set JRE_HOME and JAVA_HOME correctly(JAVA_HOME points to jdk folder and JRE_HOME to jre folder). But gradlew sees wrong jdk path. What may caurse this problem?

It is currently set to "C:\Program Files\Java\jre1.8.0_131"
That means you do not have a JDK installed, but a JRE, meaning, you only have the runtime environment but not the development kit that contains the compiler.
Install a Java JDK and set the environment accordingly.

Related

JDK 11 as JAVA_HOME?

Can the JAVA_HOME environment variable refer to JDK 11 (e.g. jdk-11.0.8) while running Codename One applications under Eclipse 2020-06?
Or does it need to point to JDK 8 (e.g. jdk-1.8.0_241)?
I am having the following error when I try to run Hello World app under Eclipse 2020-06 when JDK 11 is set to JAVA_HOME:
BUILD FAILED
...[shortened for brevity]...\HiWorldPrj\build.xml:106: 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.
It is currently set to "C:\Program Files\Java\jre1.8.0_241"
I am positive JAVA_HOME points to JDK 11 (because I can echo it from command line).
But I think I got this error because tool.jar is removed in JDK versions 9 and up and com.sun.tools.javac.Main used to be under tools.jar?
Yes you can use JDK 11 but your problem seems that the JAVA_HOME is set to the JRE and not the JDK.
Check this answer. The JRE alone cannot compile Java code.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre1.8.0_241"
Find where your JDK 11 directory is and set the JAVA_HOME environment variable to that path.
However I recommend that you set the Java in the Eclipse configuration tab. You'll find that at "Windows menu -> Java -> Installed JREs".
Update 1
It seems that Codename One uses JAVA_HOME, it is set up in the build.xml. So forget what I said about the Eclipse variables for now.
<property name="javaHome" value="${env.JAVA_HOME}"/>
Make sure your environment variable JAVA_HOME is set to the JDK 11. You can see dos on how to set that here.
Update 2
Also, you'll need to update every source="1.5" and target="1.5" in the build.xml file to either 1.8 or 11.
Example of the change in the eclipse.ini:
-vm
C:/Users/evand/Downloads/openjdk-11.0.2_windows-x64_bin/jdk-11.0.2/bin/javaw.exe
Your JAVA_HOME refers to the JRE, and JRE does not contain javac Java Compiler.
You need to point your JAVA_HOME environment variable to the JDK, i.e. the root directory of the Java binaries.
If your console prints the address of JDK 11 when you echo JAVA_HOME, then it might be that your IDE is configured to override that variable with the JRE directory when you're using that IDE.
Alternatively, your IDE can be using its bundled JRE, and your system might be referring to another Java binaries (JDK, in your case).

Error when building Ionic APP using Cordova

(node:16112) UnhandledPromiseRejectionWarning: CordovaError: Failed to run "javac -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: C:\Program Files (x86)\Java\jre1.8.0_171
I checked my user environment variable and I have the variable JAVA_HOME and set to "C:\Program Files (x86)\Java\jre1.8.0_171"
I also have C:\Program Files (x86)\Java\jre1.8.0_171 appended to the user environment variable PATH.
make sure you have a JDK installed
This is the relevant part of this error message. Your JAVA_HOME points to a Java Runtime Environment (JRE), not to a Java Development Kit (JDK).
javac is the Java compilation command, which Cordova is attempting to execute in this case. However, javac is not shipped with the JRE as it is a development tool.
You need to download and install a JDK and set JAVA_HOME to point to it

Installing ANT - unable to locate tools.jar

I am trying to install Apache Ant on my system, while setting the path variable. I have jdk installed on my system. I set the ANT_HOME environment variable to where ant is located on the system, i.e, F:\apache-ant-1.9.6\, and the path variable to F:\apache-ant-1.9.6\bin.
But when I test if ANT is installed correctly by typing ant -version on cmd , I get this error:
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.
0_25\lib\tools.jar
Apache Ant(TM) version 1.9.6 compiled on June 29 2015
While reading this answer, they say tools.jar in included in jdk and not jre. But I have correctly installed jdk, and set the environment variable correctly for that too.
When you actually go to the location specified by ant build it'll not have tools.jar.
The error is misleading and wrong. It is just because either JAVA_HOME is not defined or not set properly. Once it is done, error would get resolved.
I was also facing same issue but after research of an 1 hour I got a solution.
In system variable set your jdk path in starting.
Variable name: Path
Variable value: C:\ProgramFiles\Java\jdk1.8.0_45\bin;C:\Users\SESA401780\AppData\Local\Android\sdk\build-tools;C:\Users\SESA401780\AppData\Local\Android\sdk\tools;...
Enter Ok Ok ... and
Open new cmd
You are most likely missing the JAVA_HOME environment variable. It looks like the java.exe you are running from the command line is finding your JRE, not your JDK. Set JAVA_HOME to the location of your JDK, and move the bin directory of your JDK to be before the JRE in your PATH and try again, should work.
As the error message says:
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.
0_25\lib\tools.jar
tools.jar is expected to be in C:\Program Files\Java\jre1.8,
but it's not there.
That path looks suspiciously like a JRE path,
not a JDK.
Make sure to set JAVA_HOME to the path of your JDK. Then it should work.
It seems that currently JAVA_HOME is pointing to the path of the JRE,
not the JDK.

BUILD FAILED in android project

compile:
BUILD FAILED
D:\adt-bundle-windows-x86_64-20131030\sdk\tools\ant\build.xml:601: The following
error occurred while executing this line:
D:\adt-bundle-windows-x86_64-20131030\sdk\tools\ant\build.xml:720: The following
error occurred while executing this line:
D:\adt-bundle-windows-x86_64-20131030\sdk\tools\ant\build.xml:734: Unable to fin
d a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre7"
path is ::C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;
C:\Windows\System32\Wind
owsPowerShell\v1.0\;
C:\Program Files (x86)\MySQL\MySQL Utilities 1.3.6\;
D:\Progr
am Files\nodejs\;E:\practicum\Softwares\apache-ant-1.9.3\bin;
E:\practicum\Softwa
res\adt-bundle-windows-x86_64-20131030\adt-bundle-windows-x86_64-20131030\sdk\pl
atform-tools;
E:\practicum\Softwares\adt-bundle-windows-x86_64-20131030\adt-bundl
e-windows-x86_64-20131030\sdk\tools
;C:\Program Files\Java\jdk1.7.0_25\lib;C:\Pro
gram Files\Java\jdk1.7.0_25\bin;
C:\Users\srinivas\AppData\Roaming\npm;
Please tell me how to refix the problem.
Make "JAVA_HOME " variable point to a JDK installation, not JRE.
You are referencing the runtime environment, not the development kit - it can't find the compiler because its not there.
It should be something like this:
"C:\Program Files\Java\jdk1.7.0_51"
However the path and the JDK version may vary on your system.
As it says
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre7"
Your JAVA_HOME is set to JRE it should be set to JDK
set your JAVA_HOME to
C:\Program Files\Java\jdk1.7.0_25\bin;
or to the version of jdk is available

Error in setting JAVA_HOME

I have recently downloaded Maven and followed the instructions given on this this page. I already have ant installed on my machine.
Now, if I want to verify that Maven is installed perfectly or not it is giving me error that JAVA_HOME is not set correctly, but same works perfectly fine for ANT.
For Maven I tried :
1. open cmd
2. type mvn -version
3. Error appeared :
C:\Users\Admin>mvn -version
ERROR: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jre7\bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation
For ANT I tried and worked :
1. open cmd
2. type mvn -version
3. Apache Ant(TM) version 1.9.1 compiled on May 15 2013
I went to the directory to check that java.exe is actually there in that directory or not and it was there. I checked the environment variables they set fine. I restarted the system and checked again but same problem. Please let me know what am I missing.
JAVA_HOME should point to jdk directory and not to jre directory. Also JAVA_HOME should point to the home jdk directory and not to jdk/bin directory.
Assuming that you have JDK installed in your program files directory then you need to set the JAVA_HOME like this:
JAVA_HOME="C:\Program Files\Java\jdkxxx"
xxx is the jdk version
Follow this link to learn more about setting JAVA_HOME:
http://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/index.html
Do not include bin in your JAVA_HOME env variable
Follow the instruction in here.
JAVA_HOMEshould be like this
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_07
JAVA_HOME = C:\Program Files\Java\jdk(JDK version number)
Example: C:\Program Files\Java\jdk-10
And then restart you command prompt it works.
Just remember to add quotes into the path if you have a space in your path to java home.
C:\Program Files\java\javaxxx\ doesn't work
but
"C:\Program Files\java\javaxxx\" does.
The JAVA_HOME should point to the JDK home rather than the JRE home if you are going to be compiling stuff, likewise - I would try and install the JDK in a directory that doesn't include a space. Even if this is not your problem now, it can cause problems in the future!
You are pointing your JAVA_HOME to the JRE which is the Java Runtime Environment. The runtime environment doesn't have a java compiler in its bin folder.
You should download the JDK which is the Java Development Kit. Once you've installed that, you can see in your bin folder that there's a file called javac.exe. That's your compiler.
JAVA_HOME should point to jdk directory like in the image with new variable, like below
PATH should point to jdk bin like below
Run the below command in your terminal and restart it.
> set JAVA_HOME="C:\Program Files\Java\jdk-xx.xx"
xx.xx is the java version

Categories