I have 2 java versions on my computer:
/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
The 1.6.0 is set to default. How can I make my java programs to run 1.7?
Tried to add:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
to my .zshrc file. But this seems to only change the path for my terminals java command.
Also tried to change the HOME symlink like this:
cd /Library/Java
mv Home Home-1.6
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/ Home
This had no effect at all.
Also tried java changer software:
http://www.guigarage.com/2013/02/change-java-version-on-mac-os/
But no effect.
Any idea how to start java programs like .app and .jar files with the 1.7 version by just clicking on them?
I believe OS X (at least 10.8) uses the following paths:
JRE: /System/Library/Frameworks/JavaVM.framework/Versions/Current
JDK: /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
Those are symlinks, which you can update to point to your 1.7 installation.
You can verify this fairly easily:
a) run which java to check which java executable is being executed. In theory, that should be /usr/bin/java.
b) run ls -la on your java executable, which should tell you where it points (/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
on my machine).
I think this should sort your .jar execution issue. If your Java application is wrapped in a .app, I believe it's a bit more complex: if memory serves, the version of java used will depend on the JavaApplicationStub being used by the .app.
$ edit ~/.profile
#Java 1.8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
export PATH=${PATH}:${JAVA_HOME}
$ java -version
java version "1.8.0_20-ea"
here are the steps:
http://ukitech.blogspot.com/2014/04/switching-version-of-java-on-mac.html
You can always add into your profile both on Mac or Linux. Just create if doesn't exist ~/.profile file and there this line:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
This should work .zshrc as well as .bash_profile are loaded only when terminal window is openned and profile when your graphical environment starts up.
Related
I'm trying to make a cross-platform JavaFX application, and it works fine on Windows and OSX machines, but not on Linux.
When I try to run it on a Linux machine using java -jar app.jar, this is what I get:
Error: Could not find or load main class app.Main
But the class app.Main is in the .jar, as shown by 'jar tf app.jar':
...
app/Main.class
...
I tried specifying the main class using java -cp app.jar app.Main but I got the same error message.
The .jar was built in Intellij IDEA, using basic JavaFX configuration.
Any help?
So, turns out the problem was that the JRE on the Linux machine was OpenJDK, which does not come with JavaFX, as noted by James_D and jewelsea
After installing the oracle JRE 8, it worked fine
Sorry for the necro post, but I had to take a few extra steps. I had JRE 8 installed, but I still had to point java_home to it.
I'm using a MAC.
The JDK locations are here:
/Library/Java/JavaVirtualMachines (verify this)
The default JDK for my machine was temurin-17.jdk
I had to change it to jdk1.8.0_301.jdk
Steps:
Open a terminal
Type:
vim ~/.bash_profile
I pasted this onto the file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
Save and exit vim:
https://phoenixnap.com/kb/how-to-vim-save-quit-exit
In the terminal, type:
source ~/.bash_profile
Restart your terminal
In the terminal, type:
java -version
Make sure it's pointing to the right version
Now navigate back to where the .jar is located.
In the terminal, type:
java -jar myapp.jar
Hope this helps.
I have a linux box (Ubuntu server 14.04). I installed jdk7 via apt-get and Oracles Java 8 manually by extracting the tarball.
How can I switch between the Java versions from a bash session?
I suppose it should be done via "alternatives", but the details are not clear to me.
Switching java is more than calling one of the two java executables. There are other binaries (e.g. javac) and some tools refer to different files within the java installation directories (think of cacerts for example).
An optimal solution would simulate the effects of having only one of the two versions installed at any time.
Example: Using maven it is possible to set JAVA_HOME, but if some process started by maven calls java, JAVA_HOME is ignored.
I think Debian has Java 8 meanwhile. Does anybody know how they deal with this issue?
Is the alternatives mechanism only usable for individual binaries or can it be used for a complete "suite", too?
You can use this command to get a list of installed jdk's and easily choose one you would like to use:
sudo update-alternatives --config javac
I'm not sure that I fully understand the question, but you could either use an environment variable in your bash session that holds the path to your java executable or you could put a symbolic link somewhere for the same purpose.
For example
export JAVA_EXEC=/usr/lib/jvm/java-8-oracle/jre/bin/java
$JAVA_EXEC -version
$JAVA_EXEC -jar cooljar.jar
Or with symlink, like the "alternatives" you mentioned
ln -s /usr/lib/jvm/java-8-oracle/jre/bin/java /usr/local/bin/java
/usr/local/bin/java -version
ln -s "${SOME_JAVA_PATH}" /usr/local/bin/java
/usr/local/bin/java -version
I have the Java 1.8.0_45 SDK installed on OSX Yosemite (10.10.4), but because of a bug in this release I need to go back to 1.8.0_25
I have downloaded and installed the earlier version (1.8.0_25) but even after a reboot java -versionstill shows 1.8.0_45.
I don't really understand where Java resides on OSX, but how can I get my system back so it uses 1.8.0_25
Try and add this to your ~/.bashrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
You can have multiple JRE/JDK's installed, by changing this path, you can specify which one you use each time you open a new shell.
Here is what I use in my .bashrc
JAVA_VERSION=7
JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
tmp="JAVA_${JAVA_VERSION}_HOME"
export JAVA_HOME=${!tmp}
export PATH=${!j}/bin:$PATH
Here, you can simply change the 7 to an 8.
This will change the JAVA_HOME, and append the bin directory to your path for general use from the command line.
note you may beed to change your java home's according to the specific release versions installed on your machine.
Ah found it, suprisingly easy:
macbook:JavaVirtualMachines paul$ cd /Library/Java/JavaVirtualMachines
macbook:JavaVirtualMachines paul$ ls
jdk1.7.0_40.jdk jdk1.7.0_45.jdk jdk1.8.0.jdk jdk1.8.0_05.jdk jdk1.8.0_20.jdk jdk1.8.0_25.jdk jdk1.8.0_45.jdk
macbook:JavaVirtualMachines paul$ sudo rm -fr jdk1.8.0_45
I have researched this and none of the solutions that I have seen have fixed my error.
What is happening is I tried to install Java EE version got the above error and then found out that I must install Java SE first. So I installed Java SE and set the JAVA_HOME variable to C:\Program Files\Java\jdk1.8.0 which is where I installed my JDK. I also put C:\Program Files\Java\jdk1.8.0\bin in my PATH variable. Still not working. I also tried the JAVA_HOME variable with C:\Program Files\Java\jdk1.8.0\bin and that didn't work. I also tried installing without the PATH variable being updated to where I put my JDK.
I'm really getting confused as to why this is happening. I've had Java before and I don't recall having this much trouble installing it.
PS I don't install from the command line I just click the download icon in Firefox and then click the download.
Try running the installer at your commandline and pass the path of the JRE instead of the JDK.
For Example:
java_ee_sdk7-windows.exe -j "C:\Program Files\Java\jre8"
I had the exact same problem and even downloading the version without JDK didn't help!
I simply installed it from the terminal with passing the JRE For Example:
java_ee_sdk7-windows.exe -j "C:\Program Files\Java\jre7"
and it worked like a charm!
I had the same problem but an additional step was required in order to install using the command line. In the command window (on my Windows 10 laptop) I had to use:
cmd /d
to tell the cmd window to ignore registry AutoRun commands before the java installation executable would run. After using cmd /d, and changing to the directory where the .exe file was at, the following worked:
java_ee_sdk-6u4-jdk7-windows-x64.exe -j "%JAVA_HOME%"
Where JAVA_HOME is a system environment variable pointing to an existing JDK installation (C:\Program Files\Java\jdk1.8.0_65).
Uninstall everything, all of it.
Then go to your Program Files folder (and (x86) folder if on a 64bit Windows) and physically remove any Java folders.
Reinstall Java SE and then the EE packages. Sometimes Windows appears to get a bit confused and you need to help it figure out what to do.
If you want to uninstall, go to the glassfish folder and open the command prompt, then type:
uninstall.exe -j <The path to your JRE>
These points may be helpful.
java EE SDK7 contains glassfish v4.0 and it compatible with JDK6 and JDK7.
java EE SDK8 contains glassfish v5.0, it compatible with only JDK7 and JDK8, not JDK 9 or beyond.
So environment variable JAVA_HOME has to point to the root directory of one of the mentioned JDK. and %JAVA_HOME%\bin should be added to environment variable path
Despite having followed all of the above, setup of java EE SDK7 gets error:
could not find the required version of the Java(TM;
as Bakudan and laf8 said,
open cmd using run, with /d /a options as followed.
cmd /d /a
and next run SDK7-setup with -j option like this command
sdk7.exe -j "%JAVA_HOME%"
note that %JAVA_HOME% enclosed BY ""
This was happening to me when I tried to run the Java EE installer. What I did, was to download from Oracle a Java EE version which didn't include the JDK, because it was already installed in my system. Problem solved!
Open regedit.
goto :HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\
set CurrentVersion to desired JDK version.
Check JavaHome and RuntimeLib path's for selected jdk version folder
Check JavaHome and RuntimeLib path's for selected jdk version folder
example: "HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\1.7".
example:
JavaHome=C:\Program Files (x86)\Java\jdk1.7.0_79
RuntimeLib=C:\Program Files (x86)\Java\jdk1.7.0_79\jre\bin\server\jvm.dll
Source: http://tech-read.com/2009/05/19/how-to-solve-error-could-not-find-java-runtime-2-environment-while-opening-an-ide/
I have jdk1.7.0 directory in /usr/lib/jvm along with other open-jdk versions. I want my Ubuntu 12.04 to treat this jdk(jdk1.7.0) as its primary jdk i.e. I dont want to use open-jdks.
When I type java -version or javac -version, both the times it returns that it is using openjdk and its jre. How can change it to jdk1.7.0?
Put something similar to following to your ~/.bashrc
export JAVA_HOME="/usr/lib/jvm/jdk1.7.0"
export PATH="$JAVA_HOME/bin:$PATH"
for loading the changes, you can just run new bash by typing "bash" :]
Change the PATH variable so that /usr/lib/jvm is listed before the directory which contains Open JDK. If you are using bash, you can do this in the .bashrc file in your home directory.