issue with java and environment variables on windows - java

I've got a curious problem. After installing java jdk 6u25 I tested the installation by typing java in the command prompt. Everything worked fine , the console displayed the usage options as expected. This was about 3 weeks ago - I recently reinstalled windows 7 on my machine- Now I would like to get started with the play framework and followed a tutorial. I got a new application with play new but couldn't use play run because of this:
play! 1.2.3, http://www.playframework.org
Ctrl+C to stop
Could not execute the java executable, please make sure the JAVA_HOME environment variable is set properly .
The funny thing is that typing java in the console still displays usage options and neither eclipse or netbeans complained about a missing jdk. Nevertheless I checked my environment variables and was surprised to find:
No reference to java at all.
Seriously I got no idea how the console, eclipse and netbeans found my java. As a first countermeasure I once again reinstalled java hoping that the installer might set the path correctly. It didn't. Now I would like your advise: Should I just create the JAVA_HOME variable ? If I do, will further versions of the jdk override the variable to point to the new version or will I have to change the variable manually everytime? What about eclipse and netbeans. I would guess that they have been downloaded with their "own" jdk. If I want to update java on my machine, will it update their versions, too ?
Update:
I set the environment variable manually and restarted the pc. Now everything works fine but I would like to know what symbolic link is. Could you just give me a link in a comment or explain briefly ?

Eclipse and netbeans use a different way of finding your java installation than command line tools likes play, ant, maven, gradle etc.
IDEs may search your registry, guess default locations, or even have the JRE prepackaged with the installation.
Command-line tools usually rely on JAVA_HOME variable. And you have to set that manually.

Should I just create the JAVA_HOME variable ?
There are several tools that use that environment variable, so I'd recommend creating it.
If I do, will further versions of the jdk override the variable to point to the new version or will I have to change the variable manually everytime?
If you install your new Java version into the same folder (or if you create symbolic links), then no.
What about eclipse and netbeans. I would guess that they have been downloaded with their "own" jdk. If I want to update java on my machine, will it update their versions, too ?
That depends on whether the JDK is prebundled and how the configuration is done. I can't speak for Netbeans but in Eclipse, you could add this to your eclipse.ini:
-vm
C:/Java/jre/bin
Note that this is an example path to the bin folder. If you don't add versions there or use symbolic links (see above) then you'd not have to update the path when installing a new version.

It is possible that you have a (older?) java.exe in C:\windows or other common directory.
Make sure that the java you get on the command line is the one you think it is:
java -version

Related

How can I change the JDK version into JDK 10 in NetBeans? [duplicate]

I have the older NetBeans 6.7, NetBeans 6.9, and NetBeans 7.0, which used to run on jdk1.6.0_21 and jdk1.6.0_25. Now I've removed those JDKs and only have jdk1.6.0_26 and jdk1.7.0 left, but I still want to keep the older versions of NetBeans, but now when I run them, I get this message:
"Cannot locate java installation in specified jdkhome C:\Program Files (x86)\Java\jdk1.6.0_25
Do you want to try to use default version?"
I tried to find where it's looking for the "jdk1.6.0_25", and updated a few configuration files in "C:\Program Files (x86)\NetBeans 6.7" and "C:\Users\USER.nbi\registry.xml", and yet the message keeps coming. Where and what do I need to change to point it to C:\Program Files (x86)\Java\jdk1.6.0_26?
Thanks to Kasun Gajasinghe's tip, I found the solution in the "suggested" link. Update the following file (replace 7.x with your NetBeans version):
C:\Program Files\NetBeans 7.x\etc\netbeans.conf
Change the following line to point it where your Java installation is:
netbeans_jdkhome="C:\Program Files\Java\jdk1.7xxxxx"
You may need administrator privileges to edit netbeans.conf.
Go to Tools* → Java Platforms. There, click on Add Platform and point it to C:\Program Files (x86)\Java\jdk1.6.0_25. You can either set the another JDK version or remove existing versions.
Another solution suggested on the Oracle (Sun) site is,
netbeans.exe --jdkhome "C:\Program Files\jdk1.6.0_20"
I tried this on 6.9.1. You may change the JDK per project as well. You need to set the available JDKs via the Java Platforms dialog. Then, go to Run → Set Project Configuration → Customize.
After that, in the opened dialog box, go to menu Build → Compile. Set the version.
For those not using Windows, the file to change is netbeans-8.0/etc/netbeans.conf.
And the line(s) to change is:
netbeans_jdkhome="/usr/lib/jvm/java-8-oracle"
Comment out the old value and insert the new value.
As a further useful solution for those of you on Windows 7 and above - if you use
cd "C:\Program Files\Java"
mklink /D jdk8 jdk1.8.0_25
you get a symbolic link folder that can be adjusted whenever a new JDK comes out.
All you need to do then is set your
netbeans_jdkhome="C:\Program Files\Java\jdk8"
(in both locations for NetBeans 8) and you never have to edit the configuration again. Just tweak the symlink each time your JDK is updated.
I had this message too because today I decided to relocate my different JDK in the same directory. I have decided to uninstall all through the program manager of Windows. After that, of course I had the message below.
"Cannot locate java installation in specified jdkhome C:\Program Files (x86)\Java\jdk1.7.0_60. Do you want to try to use the default version?"
A new install of the JDK does not resolve the problem. OK, you can configure that in menu Tools → Java platforms, but in my case I had to fix my netbeans.conf file.
I had the line below:
netbeans_jdkhome="C:\Program Files\Java\jdk1.7.0_60"
And I replaced it by:
netbeans_jdkhome="C:\devtools\Java\jdk1.8.0_25"
It does not exactly answer your question, but to get around the problem,
you can either create a .cmd file with following content:
start netbeans --jdkhome c:\path\to\jdk
or in the shortcut of Netbeans set the above option.
Where you already have a project in NetBeans and you wish to change the compiler (e.g. from 1.7 to 1.) then you would need to also change the Java source compiler for that project.
Right-click on the project and choose Properties as outlined below:
Then check that the project has the necessary source circled below:
Then check that the Java compiler is correct for the project:
All the other answers have described how to explicitly specify the location of the Java platform, which is fine if you really want to use a specific version of Java. However, if you just want to use the most up-to-date version of the JDK, and you have that installed in a "normal" place for your operating system, then the best solution is to not specify a JDK location. Instead, let the NetBeans launcher search for the JDK every time you start it up.
To do this, do not specify jdkhome on the command line, and comment out the line setting netbeans_jdkhome variable in any netbeans.conf files. (See other answers for where to look for these files.)
If you do this, when you install a new version of Java, your NetBeans installation will automagically use it. In most cases, that's probably exactly what you want.
In Windows, open cmd.
Go to the directory where your NetBeans file downloaded.
Then run the below command. The JDK path may be different from the path I mentioned.
netbeans-8.2-windows.exe --javahome "C:\Program Files\Java\jdk-9.0.1"

does eclipse have it's own JDK? or it uses the JDK on my computer?

I'm new to java programming and I haven't used any java IDE,
I intalled Java JDK 8 on my computer and been doing some coding through Notepad++ and compiling it via cmd commands.
Since now that i'm comfortable coding manually, I wanna try to use IDE and decided to get the latest "Eclipse IDE for Java Developers". what I got is actually a .zip file no installation or something which is odd.
My question is does the eclipse uses the JDK I installed on my computer or it has it's own? if so how would I know which version of java does my eclipse run?
and if does use the JDK on my computer, if I want to update the JDK intalled on my computer do I have to uninstall the old one or I can just overwrite it with the new JDK build??
Thanks,
CC
Eclipse uses externally installed JDKs to run itself (it's written in Java, after all) and to provide the core libraries for the code you write (such as the java.* packages). By default, Eclipse will use its own compiler, ECJ, that has deep integrations with the IDE to provide features such as detailed error reporting and sometimes even partial compilation of invalid classes.
It's possible to override the compiler via some plugin (for example, you can explicitly specify a compiler in a POM via m2eclipse, though the default there still uses ECJ), but that's uncommon if you're still compiling Java code.
Eclipse has support for using multiple JDKs, for example for different versions (maybe you have backwards compatibility with 1.6) or different vendors. Depending on how your OS is set up, if your main JAVA_HOME is set through a symlink, you may not need to update Eclipse at all if you perform a minor upgrade. In the case of a major upgrade, though, you will probably need to go to "Installed JREs" and add or modify an entry.
1.the jdk you installed in your computor is global situation. it can effect anywhere if you have configured the environment variables.
2.configured the environment variables,run cmd like this,the java version will be show,enter image description here
3.generally, one JDK , one computor is enough.if you want to update jdk, just download new jdk and override the old jdk .

Running Multiple Java Versions

Hopefully someone can help me because I am apparently brain dead. I have searched and read through a lot of this forum as well as others for help in resolving my problem and I am just not getting it.
I have 2 Java WebApps that I need to run for Johnson Control HVAC units. The one unit is old and strictly requires Java 1.6.0_21. There are no upgrade options available for this unit. Just hundreds of thousands of dollars to replace the whole system. But the system works just fine so I am not interested in replacing it.
Now I have another unit which my company just took over at another location that uses a similar control unit but runs on Java 1.7.0_49 or 69 I can't remember. I have both versions installed on my computer but only the newer unit with Java 1.7 works. My older one now comes up with Unable to Launch Application Error. I have tried all these things and either I am just plain doing it wrong or something else that I am not catching is up.
I tried going into the Java Control Panel and unchecking Enable 1.7. That had no affect, even after rebooting.
I went into the Environmental Variables and under Path I have no Path to Java. So I added the path to the Java 1.6 version which also had no affect.
I have a batch file on my desktop to run the older app because it's web URL is a mile long. In this batch file I tried to add set JAVA_HOME variable and a set PATH variable for Java 1.6 which also had no affect.
I tried just doing java -version:1.6 from the cmd prompt which also did not allow the program to start.
I got it so when I did java -version from the cmd prompt it would tell me 1.6.0_21 for the version but I still can't get the program to load.
So I uninstalled 1.7 from the computer and tried it again. Still would not load the program. I had to reinstall the 1.6 before the older program worked. But once I reinstalled 1.7 I was back in the same boat.
I tried re-installing both programs using the STATIC=1 command through cmd prompt and still only version 1.7 runs and the older 1.6 does not.
I do get a message when I try to load the 1.6 that says, the program has requested an older outdated version of the program. Open with new version recommended or open in the older requested version 1.6.0_21. I select open in the older version but still get the Can Not Launch Application Error.
I have also tried going into the advanced settings and unchecking Internet Explorer for the Browser in the 1.7 control panel and going into the 1.6 control panel and checking Internet Explorer.
What am I doing wrong here or what am I missing? Any help would be appreciated.
This is a Windows XP 32 bit computer. Nothing special, just a word processor mostly.
You are swimming upstream, but it isn't a very large or strong stream, and this can be done.
The upstream part is that most instructions for doing this assume you are going to run only one version of the JVM on a given machine.
The good news is that Java doesn't require this, and is not set up so that it is difficult to run two at the same time. You just have to be rigorous about where each of them get their information.
I would recommend not "installing" EITHER of them. Do not put the executables' or the libraries' directories on your path variable, and do not define a CLASSPATH variable on the machine globally. You will need to unpack a runtime environment for each JVM, each in their own directory tree.
Make one batch file to run each version. It will define its own path variable, and its own classpath (either with SET CLASSPATH= or using the classpath JVM argument).
Good luck.

Missing JRE in Eclipse in Mac OSX

I'm trying to run eclipse on my Mac OS X. I've been doing some Android programming on Eclipse lately, and today wanted to do some development on Java. However, to my surprise, Eclipse says there's no JRE/JDK installed. I don't know how this is possible, since my android projects have worked very well so far, and even now. I've tried the following items:
Checking java version through the Mac terminal. It says java version "1.8.0_20" is installed. Here's the screenshot.
I've checked the Java version through the Java Control Panel in System Preferences. Again, same thing:
I know that when there's no JRE visible in Eclipse, it can be manually entered through the "add" option under preferences > Java > Installed JREs in Eclipse. But although I can find the Contents folder in this path: /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/home/contents, when I attempt to manually add this in Eclipse, the Java folder under users/library just doesn't show up. I have no idea why this is happening. Here are some screenshots, just in case:
As you can see, the Java folder just doesn't show up under Library in the above screenshot.
Lastly, I've also tried to hit "Search" in Eclipse (same place as "Add" in one of the screenshots above), but "Search" doesn't find anything at all.
I've gone through existing answers on SO which deal with similar problems. The only thing which I haven't done seems to be about setting a path variable, but they were all in Windows OS, so not sure if it applies in my situation.
I'd really appreciate any help on this.
Update 1: According to what has been pointed out so far, I tried copy-pasting the suggested path. But the error I get is: The home directory does not exist.
Here's the screenshot:
You are trying to find the JRE in a wrong Library directory as Library directory maybe present in more than one place. Just copy paste the jre path in 'jre home' input as
/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/home/contents/Home/jre/
EDIT: To find where is your java installed on Mac, run the following command:
echo $(/usr/libexec/java_home)
it should return something like this:
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
append jre to the end of this path to build JRE home path:
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre

How can I set the JDK NetBeans runs on?

I have the older NetBeans 6.7, NetBeans 6.9, and NetBeans 7.0, which used to run on jdk1.6.0_21 and jdk1.6.0_25. Now I've removed those JDKs and only have jdk1.6.0_26 and jdk1.7.0 left, but I still want to keep the older versions of NetBeans, but now when I run them, I get this message:
"Cannot locate java installation in specified jdkhome C:\Program Files (x86)\Java\jdk1.6.0_25
Do you want to try to use default version?"
I tried to find where it's looking for the "jdk1.6.0_25", and updated a few configuration files in "C:\Program Files (x86)\NetBeans 6.7" and "C:\Users\USER.nbi\registry.xml", and yet the message keeps coming. Where and what do I need to change to point it to C:\Program Files (x86)\Java\jdk1.6.0_26?
Thanks to Kasun Gajasinghe's tip, I found the solution in the "suggested" link. Update the following file (replace 7.x with your NetBeans version):
C:\Program Files\NetBeans 7.x\etc\netbeans.conf
Change the following line to point it where your Java installation is:
netbeans_jdkhome="C:\Program Files\Java\jdk1.7xxxxx"
You may need administrator privileges to edit netbeans.conf.
Go to Tools* → Java Platforms. There, click on Add Platform and point it to C:\Program Files (x86)\Java\jdk1.6.0_25. You can either set the another JDK version or remove existing versions.
Another solution suggested on the Oracle (Sun) site is,
netbeans.exe --jdkhome "C:\Program Files\jdk1.6.0_20"
I tried this on 6.9.1. You may change the JDK per project as well. You need to set the available JDKs via the Java Platforms dialog. Then, go to Run → Set Project Configuration → Customize.
After that, in the opened dialog box, go to menu Build → Compile. Set the version.
For those not using Windows, the file to change is netbeans-8.0/etc/netbeans.conf.
And the line(s) to change is:
netbeans_jdkhome="/usr/lib/jvm/java-8-oracle"
Comment out the old value and insert the new value.
As a further useful solution for those of you on Windows 7 and above - if you use
cd "C:\Program Files\Java"
mklink /D jdk8 jdk1.8.0_25
you get a symbolic link folder that can be adjusted whenever a new JDK comes out.
All you need to do then is set your
netbeans_jdkhome="C:\Program Files\Java\jdk8"
(in both locations for NetBeans 8) and you never have to edit the configuration again. Just tweak the symlink each time your JDK is updated.
I had this message too because today I decided to relocate my different JDK in the same directory. I have decided to uninstall all through the program manager of Windows. After that, of course I had the message below.
"Cannot locate java installation in specified jdkhome C:\Program Files (x86)\Java\jdk1.7.0_60. Do you want to try to use the default version?"
A new install of the JDK does not resolve the problem. OK, you can configure that in menu Tools → Java platforms, but in my case I had to fix my netbeans.conf file.
I had the line below:
netbeans_jdkhome="C:\Program Files\Java\jdk1.7.0_60"
And I replaced it by:
netbeans_jdkhome="C:\devtools\Java\jdk1.8.0_25"
It does not exactly answer your question, but to get around the problem,
you can either create a .cmd file with following content:
start netbeans --jdkhome c:\path\to\jdk
or in the shortcut of Netbeans set the above option.
Where you already have a project in NetBeans and you wish to change the compiler (e.g. from 1.7 to 1.) then you would need to also change the Java source compiler for that project.
Right-click on the project and choose Properties as outlined below:
Then check that the project has the necessary source circled below:
Then check that the Java compiler is correct for the project:
All the other answers have described how to explicitly specify the location of the Java platform, which is fine if you really want to use a specific version of Java. However, if you just want to use the most up-to-date version of the JDK, and you have that installed in a "normal" place for your operating system, then the best solution is to not specify a JDK location. Instead, let the NetBeans launcher search for the JDK every time you start it up.
To do this, do not specify jdkhome on the command line, and comment out the line setting netbeans_jdkhome variable in any netbeans.conf files. (See other answers for where to look for these files.)
If you do this, when you install a new version of Java, your NetBeans installation will automagically use it. In most cases, that's probably exactly what you want.
In Windows, open cmd.
Go to the directory where your NetBeans file downloaded.
Then run the below command. The JDK path may be different from the path I mentioned.
netbeans-8.2-windows.exe --javahome "C:\Program Files\Java\jdk-9.0.1"

Categories

Resources