Change JDK to another version issue - windows

I have started on a project that specifically says that use 1.6 JDK to prevent form test failings.
I came across a peculiar behavior while I tried to change JDK from 1.7 to 1.6.
Even though I changed environment variables form 1.7 to 1.6 JDK version, When I run java.exe -version or java -version in cmd, it still gives the earlier version. But when I run javac -version it gives the 1.6 version.
What I did so far was,
In User Environment variables,
classpath to C:\Program Files\Java\jdk1.6.0_43(JDK installation path)
Added java_home variable and changes path to C:\Program Files\Java\jdk1.6.0_43(JDK installation path)
Changed path to C:\Program Files\Java\jdk1.6.0_43\bin(Java bin)
In system Environment variables,
Added C:\Program Files\Java\jdk1.6.0_43\bin to CLASSPATH
Created JAVA_HOME Variable and added C:\Program Files\Java\jdk1.6.0_43\bin
There was a variable that is related to Java, called QLJAVA and path was set to C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip and I removed that variable as well.
Before I edited the CLASSPATH this is the same path that was there
My issues,
Why it selects 1.7 when used java -version, and why gives different result when ran javac -version. or is there something wrong with what I already have done?
What is the QLJAVA variable and what is the use of it and how did
end up in system variables.?
Why to change to 1.6 is not there any backword compatibility.?

Here are some of the guidelines when setting up environment variables for java.
JAVA_HOME should point to the java installation path
PATH should include %JAVA_HOME%/bin
I usually setup different java version as different environment variables and switch them up by changing JAVA_HOME
eg.
JAVA_6=c:\jdk6
JAVA_7=c:\jdk7
JAVA_HOME=%JAVA_6% (or JAVA_HOME=%JAVA_7%)
PATH=%JAVA_HOME%\bin;%PATH%
Also, some other entries in the path may point to a different version of Java so I usually add the %JAVA_HOME%\bin entry first.
Also, when making changes to environment variables, you should close and open a new cmd instance to have the environment variables reloaded.
Lastly, having spaces on your paths can have an effect. You might need to add quotes to them or use the old variable convention of DOS. eg. PROGRA~1 instead of Program Files.
To answer your issues:
your PATH environment variable points to different paths for java and javac. Just set the %JAVA_HOME%\bin as the first entry to the PATH variable and it should pick up the right version of JAVA you want.
As for QTJAVA, I haven't encountered it yet so I can't give a concrete answer. As for how it got there, well, some Software/Programs modify the environment variables when you install them so they got there that way.
It should be backward compatible or tries to be. I haven't seen the code nor have really tried JDK 7 long enough but according to the issue on the link you gave (https://tickets.openmrs.org/browse/TRUNK-3142), it looks like a JDK 7 issue.
Hope this helps.

The loader java.exe is normally placed in the Windows\System32 directory, though there are also copies in the JDK. The compiler javac.exe is always in the JDK. This is the root of what you're seeing.
There's an excellent chance that a copy java.exe appears in a folder that's earlier in your path than Windows\System32\java.exe.
It's also possible installation of v1.6 is failing to overwrite the old java.exe because you don't have enough permission to write in Windows\System32, though an error should be provided in this case.
The best way I know to figure out what is happening is to install a which.exe command, which you can find in Cygwin or MinGW. When you say which java.exe, you'll see the path to the java.exe v1.7 that is causing the problem. Adjust your path, delete, or rename the file.

Related

IntelliJ IDEA - No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

I am trying to clean maven project using IntelliJ on mac by running below command but getting error. Please suggest what needs to be done to fix this
./mnwn clean package
Error : "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?"
Thanks
The issue is not related to IntelliJ IDEA, you should get the same behavior when you run this command in the system Terminal.
To fix the issue install any JDK on your system and make sure the bin subdirectory of the JDK home directory is added to PATH environment. You may also want to set JAVA_HOME environment variable pointing to this JDK installation home directory.
To verify that it works run java -version in the system Terminal. Make sure it prints the correct Java version of the JDK and not a JRE.
I was facing similar error while workspace setup on a new MAC system.
I was initially referring "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin" as JAVA_HOME path but it was not correct.
The correct JDK path was "/Library/Java/JavaVirtualMachines/jdk1.8.0_331.jdk/Contents/Home". If you JDK with default installation path on MAC then cross check your JAVA_HOME. It might help you to solve your problem.

Why Does My Kotlin Code Compile In IDEA And Not In Gradle? [duplicate]

I am using javadoc doclets with gradle, so I need to use the package tools.jar, which is in the lib folder from the jdk (1.6.0_26 in my case).
The point is that gradle does not take it automatically, so I was adding that tools package to my libs folder, and then adding it to dependencies.gradle .
Now I want to take it directly from my JDK home into my dependencies.gradle. Is there a way to do that? I have tried the next in my dependencies.gradle:
compile files("${System.properties['java.home']}/lib/tools.jar")
But it does not find it while compiling.
I had this problem when I was trying to run commands through CLI.
It was a problem with system looking at the JRE folder i.e.
D:\Program Files\Java\jre8\bin. If we look in there, there is no Tools.jar, hence the error.
You need to find where the JDK is, in my case: D:\Program Files\Java\jdk1.8.0_11, and if you look in the lib directory, you will see Tools.jar.
What I did I created a new environment variable JAVA_HOME:
And then you need to edit your PATH variable to include JAVA_HOME, i.e. %JAVA_HOME%/bin;
Re-open command prompt and should run.
Found it. System property 'java.home' is not JAVA_HOME environment variable. JAVA_HOME points to the JDK, while java.home points to the JRE. See that page for more info.
Soo... My problem was that my startpoint was the jre folder (C:\jdk1.6.0_26\jre) and not the jdk folder (C:\jdk1.6.0_26) as I thought(tools.jar is on the C:\jdk1.6.0_26\lib folder ). The compile line in dependencies.gradle should be:
compile files("${System.properties['java.home']}/../lib/tools.jar")
I got the same error using Eclipse trying to execute a Gradle Task. Every time I run a command (i.e. war) the process threw an exception like:
Could not find tools.jar. Please check that C:\Program Files\Java\Jre8" is a valid JDK install.
I tried the solution listed in this post but none of them solved this issue. Here my solution :
Go to the "Gradle Task" view
Right Click on the task you want to execute
Select Open Gradle Run Configuration
In the tab "Java Home" select your local JDK repository then click OK
Run again, Enjoy!
I just added a gradle.properties file with the following content:
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_45
I had a similar case using Ubuntu. The machine had only the JRE installed. So, I just executed the command below to install the JDK.
sudo apt install openjdk-8-jdk
In macOS Big Sur
The issue happens because of the environment variable JAVA_HOME is not correctly set in macOS Big Sur.
Step 1 - Confirm that you have issue with JAVA_HOME by printing its value in the terminal. You will most likely get an empty string.
echo $JAVA_HOME
Step 2 - Find the correct path on your machine
/usr/libexec/java_home -V
Copy that path associated with "Java SE 8" which usually looks like /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
Step 3 - Edit .zshenv using nano
nano ~/.zshenv
Step 4 - Add the path from step 2 to the file as follows
export JAVA_HOME=YOUR_JAVA_PATH
example:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
Step 5 - Source the updated .zshenv file to activate the environment variable
source ~/.zshenv
Step 6 - Print to confirm the path
echo $JAVA_HOME
I was struggling as well for this Solution. Found a better way to it with Gradle as described here.
We can get the JVM/JDK information from Gradle itself.
dependencies {
runtime files(org.gradle.internal.jvm.Jvm.current().toolsJar)
}
So simple.
In CentOS7 the development package will install tools.jar. The file is not present in java-1.8.0-openjdk
sudo yum install java-1.8.0-openjdk-devel
Add this to gradle.properties:
org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_91
My solution on Mac:
add this line to gradle.properties:
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
not this one:
org.gradle.java.home=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
you can open the last home directory and will find that there is no lib/tools.jar file existence, so change the path to JavaVirtualMachines/jdk1.8.0_271.jdk and it works for me.
By the way, in the terminal, I echo the $JAVA_HOME and it gets the first path, not the second one, I think this is why my Gradle cannot work properly.
With Centos 7, I have found that only JDK has tools.jar, while JRE has not. I have installed the Java 8 JRE(yum install java-1.8.0-openjdk), but not the JDK(yum install java-1.8.0-openjdk-devel).
Installing the latter solves the problem. Also, remember to set JAVA_HOME.
It may be two years too late, but I ran into the same problem recently and this is the solution I ended up with after finding this post:
import javax.tools.ToolProvider
dependencies {
compile (
files(((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs()),
...
}
}
It should work if java.home points to a directory that's not under the JDK directory and even on Mac OS where you'd have classes.jar instead of tools.jar.
On windows 10, I encounter the same problem and this how I fixed the issue;
Access Advance System Settings>Environment Variables>System
Variables
Select PATH overwrite the default
C:\ProgramData\Oracle\Java\javapath
With your own jdk installation that is JAVA_HOME=C:\Program Files\Java\jdk1.8.0_162
On my system (Win 10, JRE 1.8.0, Android Studio 3.1.2, Gradle 4.1) there is no tools.jar in the JRE directory (C:\Program Files\Java\jre1.8.0_171).
However, I found it in C:\Program Files\Android\Android Studio\jre\lib and tried setting JAVA_HOME=C:\Program Files\Android\Android Studio\jre
That works (for me)!
What solved it for me was the following:
found tools.jar in C:\Program Files\Android\Android Studio\jre\lib
copy paste to C:\Program Files (x86)\Java\jre1.8.0_271\lib
ran the code again and it worked.
If you use terminal to build and you have this error you can point to jdk bundled with android studio in your gradle.properties file:
org.gradle.java.home=/usr/local/android-studio/jre
Linux
Open /etc/environment in any text editor like nano or gedit and add the following line:
JAVA_HOME="/usr/lib/jvm/open-jdk"
Windows
Start the System Control Panel applet (Start - Settings - Control
Panel - System).
Select the Advanced tab.
Click the Environment
Variables button.
Under System Variables, click add button, then past the following lines:
in Variable Name : JAVA_HOME
in Variable Value : C:\Program Files\Java\jdk1.x.x_xxx
where x.x_xxx jdk version you can get your jdk version from here C:\Program Files\Java
Under System Variables, select Path, then click Edit,then click new button then past the following line:
%JAVA_HOME%/bin;
This worked for me:
I was getting message
Execution failed for task ':app:compileDebugJavaWithJavac'.
Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_121 contains a valid JDK installation.
In Android Studio, check your SDK Location.
File, Project Structure, SDK Location, JDK Location.
Example: C:\android-studio\android-studio\jre
Copy the tools.jar file in the C:\android-studio\android-studio\jre\lib folder into the C:\Program Files\Java\jre1.8.0_121\lib folder.
Retry.
Like other answers I set org.gradle.java.home property in gradle.properties file. But path with \ separators did not work (building on windows 10):
Java home supplied via 'org.gradle.java.home' is invalid. Invalid
directory: C:Program FilesJavajdk1.8.0_65
So instead of
org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_65
i had to use
org.gradle.java.home=C:/Program Files/Java/jdk1.8.0_65
then the build was successful
Problem is that project is build with JRE instead of JDK and since I was building it from eclipse this also worked:
In Window>Preferences>Gradle>Arguments specify Workspace JRE and specify your JDK.
In Window>Preferences>Java>InstalledJREs specify your JDK as default
In my case (Windows 10) after Java update I lost my Enviroment Variables, so I fixed added the variables again, based in the following steps https://confluence.atlassian.com/doc/setting-the-java_home-variable-in-windows-8895.html
I solved problem on this way:
download file tools-1.8.0.jar on http://www.java2s.com/Code/Jar/t/Downloadtools180jar.htm
unzip file and rename to tools.jar
copy to C:\Program Files\Java\jre1.8.0_191\lib folder
Retry
Put in gradle.properties file the following code line:
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_45
Example image
Use this with modern versions of gradle:
def compiler = javaToolchains.compilerFor { languageVersion = JavaLanguageVersion.of(java.sourceCompatibility.majorVersion) }.get()
implementation compiler.metadata.installationPath.files('lib/tools.jar')
Did you make sure that tools.jar made it on the compile class path? Maybe the path is incorrect.
task debug << {
configurations.compile.each { println it }
}
Adding JDK path through JAVA_HOME tab in "Open Gradle Run Configuration" will solve the problem.
Could not find tools.jar
MacOS
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
And restart Shell
I've tried most of the top options but it seems that I had something wrong with my environment setup so they didn't help. What solved the issue for me was to re-install jdk1.8.0_201 and jre1.8.0_201 and this solved the error for me. Hope that helps someone.
For me this error ocurred after trying to use audioplayers flutter library.
To solve i got tools.jar of the folder:
C:\Program Files\Android\Android Studio\jre\lib
and pasted on
C:\Program Files\Java\jre1.8.0_181\lib.
After this the build worked fine.
My Android Studio Version: 4.2.1
The "tools.jar" is provided by Oracle JDK which is required by android studio for compilation - I have faced this issue after updating android studio to latest version in my PC.
To Resolve the issue follow below steps:
In Android studio File -> Project Structure -> SDKs (Under Platform Settings)
A) Add JDK path by pressing '+' symbol in middle pane if suppose JDK/JDK home path is not present in the middle pane already (Middle pane also contains the Downloaded Android SDK's)
B) Java sdk will be usually present/installed in the path 64 bit => "C:\Program Files\Java\jdk1.X.Y_ABC" (In my PC it is 1.8.0_202) or 32 bit => "C:\Program Files (x86)\Java\jdk1.X.Y_ABC"
If suppose you don't have JDK installed in your PC,
please download and install from Oracle Java website
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
Set JDK and JRE Path(Download both from webpage mentioned in step 2) in system environment variable
A) Press windows key type "Edit the system environment variables" and open the application
B) Go to Advanced -> Environment Variables Under system variables add JAVA_HOME and JRE_HOME as below
Set Windows system environment variable
Add jdk lib path on the Path environment variable under user variables (this step is required only if the error not resolves with the previous steps)
C:\Program Files\Java\jdk1.X.Y_ABC\lib
For Windows add JDK home path to the Gradle property file as org.gradle.java.home.
If you don't have gradle.properties file then create a new one and add
Ex: org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_241

Can't locate JDK on Windows 7

I believe similar questions have been asked before, but none of them matches mine perfectly. So I'm posting this one.
I'm using the Eclipse IDE in ADT bundle. Currently I'm doing some basic Java programming. Prior to this, I had downloaded and installed JDK from Orcale. The problem occurred when trying to set up Javadoc, as it needed the path to javac. Now, if I try where java, I get C:\Windows\System32\java.exe. If I try where javac, I get not found error. To complicate matters even further, echo %PATH% gives (I've added newlines for clarity):
C:\Program Files\Java\jdk1.7.0_03\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Common Files\GTK\2.0\bin;C:\Python32;C:\Program Files\Calibre2\
But guess what, there's no folder by the name of jdk1.7.0_03 in the Program Files\Java directory! All I have is the "jre" folder.
I'm thoroughly confused. Where is the javac program? Where was the JDK installed? Am I missing something important here? Please help!
First download the jdk from oracle. During the installation, you should find a path to install your jdk, for example, C:\Program Files\Java\jdk1.7.0_05\bin. Then you should set up the environment variable for your jdk in Control panel -> System -> Advanced -> Environment Variables. The detail can be found in this post.
The javac file is usually in C:\Program Files\Java\jdk1.7.0_03\bin\javac
If you can't find it in that path, maybe the one that you installed is not jdk or maybe it is the wrong jdk. You don't need to install JRE, the JDK package has already contained JRE in it.
If you can't find javac in that path, maybe you installed the wrong java executable. Try to uninstall Java and install it again using the newest update.
Don't forget to set the CLASSPATH.

configure the jre version on windows 7 (32 bit)

I have java jre7 installed and also jre6, but the current version that is in use is the jre7. How do I tell windows to use the jre6 instead of 7? I've seen some guides of how to do so but it seems that they related to winXP since they were dealing with the JAVA_HOME variable (which does not exist on win7).
I've tried to add the path of the bin folder of the jre6 to the PATH environment variable but it didn't work. Do you have any other ideas?
By the way - I do want my eclipse to run the jre7, so I figured out I need to add/change lines in the eclipse.ini file, what exactly do I need to do there?
Thanks in advance,
Guy
Like on other windows versions (and by the way like on linux too), you have to set the JAVA_HOME environment variable.
If this var doesn't exist yet, it simply means you have to create it.
Here's how you can set an env variable on Win7 : http://www.windows7hacker.com/index.php/2010/05/how-to-addedit-environment-variables-in-windows-7/
For Eclipse, go in the preferences, choose java/installed JREs and choose the one you want. But for most of your other java based programs, the JAVA_HOME is really the important variable (along with the PATH).

How to prevent that java.exe is installed in Windows' system32?

Is there a way to prevent that the Java installation routine (e.g. jdk-7u1-windows-i586.exe) copies java.exe into C:\Windows\system32 directory?
I have to install my software on a client's laptop and I don't want to break other Java applications which are already installed on the machine. In other words I want to install a private JRE which is only used by my software.
By now, I copied an already installed JRE from my computer to the client's machine.
I discovered yesterday that there is a problem with Java versions on Windows, as you know keeping java up to date these days is critical, especially the JRE used by Internet explorer located in the Windows system32 or syswow64 folder.
You can perform a search for java in your C: drive and look at the various executable files it finds to determine if the situation applies on a specific system.
After doing some research I find that when the Java updater runs, it only updates the files installed in the JAVA home , usually located on the program files, but it does NOT update the files located in the windows system folder. As a result and since the system folder is in the default system PATH , the usage of Internet Explorer continues to use an old version of the JAVA files ( java.exe , javaw.exe , javaws.exe )
The solution is to uninstall java using the control panel uninstall programs feature, download most recent version and install again.
Cheers!
Fernando
I recently upgraded to java 8 and discovered this problem as the java version under system32 was still java 7. It stops you even running version as it complains about the registry keys
U:\>java -version
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
Doing the following pointed me to the culprit:
U:\>where java
C:\Windows\System32\java.exe
C:\Program Files\Java\jdk1.8.0_45\bin\java.exe
I 'solved' this problem by just deleting the java under system32! I'm unsure of what consequences this will have.
You can just provide the JRE you want to use on your software and:
Set the JAVA_HOME variable before you run your application
Point to the correct java.exe file (e.g. ..\jre1.5.0_22\bin\java <your_java_main>)
This can be done in a *.bat file for example.
After running the *.bat file you created, all other java version will be ignored and it won't matter which versions are, or will be, installed on that pc.
I found the newest JDK still doesn't write correct code against registry.
The issue is if a computer doesn't have JRE, JDK doesn't register JRE in registry correctly.
For those install JDK 1.7u72 Just add Software\JavaSoft\Java Runtime Environment as the error message indicate. And add a string entry of CurrentVersion with value 1.7.
And then add Software\JavaSoft\Java Runtime Environment\1.7 and put a JavaHome string entry with value "C:\Program Files\Java\jre7". And JRE will function correctly.
Blame Oracle, if you use Registry, then write correct code, otherwise don't use the Registry!
All you have to do is go to Control Panel -> Programs Uninstall a program. Uninstall the old java updates and keep the newest java update and java development kit update. Your newest java update and java development kit update should have the same number.
Windows 10 Solution
Check Java Version in Console (CMD) with java -version
Check in Console (CMD) with where java, which Java Path's are enlisted.
If it you shows you "C:\Windows\System32" in its output, you will have a problem to get to your %JAVA_HOME%, where your wanted Java version resides.
Meaning, you need to get rid of "java.exe" in "C:\Windows\System32".
Just uninstall the JRE in the Software ("Programs and Features")
Hint: Keep in mind, do NOT the JDK, here in my case "Java SE Development Kit 8 Update (64-bit)"), but the JRE.
One way I would try would be to create a write-only empty file with the name java.exe into the System32 folder.

Resources