Setting Java home enviroment variable in OSX Mavericks - java

I am having issues with my Java path.
I have installed the latest version of Java 1.7.0_51. When I open the Java control panel it tells me "Your system has the recommended version of Java."
However when I go to terminal and type java -version I get
java version "1.6.0_32"
So after searching around I came across this SO Question which tells me that my Java home environment variable needs to be set.
I then opened the bash_profile file and added the below line to the top of the file, above my Python path info.
export JAVA_HOME=`/usr/libexec/java_home -v 1.7.0_51`
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
NOTE: I have tried this with both -v 1.7.0_51 and -v 1.7
I save the file and recheck in terminal but it is still showing
java version "1.6.0_32"
when I restart Terminal I do however see
Last login: Wed Feb 19 23:32:19 on ttys000
Unable to find any JVMs matching version "1.7".
localhost:/ user$
Note: Unable to find any JVMs matching version "1.7".
So it is trying to look for my 1.7, but just not finding it.
What am I doing wrong?

Check whether there is an old version existed in the path
echo $PATH
Then set the java 1.7 bin directory.
export PATH=/usr/libexec/java_1.7_home/bin:$PATH
Then try to type in "java -version" in terminal to check the version

Ok, I think this must be specific to me. As above the Java control panel was saying that java 7 was installed. Also when i tried
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
I would get
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
But no mater what way I installed the JDK it would not work. It just didn't seem to appear anywhere on my machine. I still don't know why, but uninstalling (by simply deleting the 1.6 folder) the existing Java 6 from my machine and once again installing Java 7 JDK eventually fixed it.
Please give the up-votes to #diaz994 above.

Related

ionic cordova run android and java version

so I'm basically trying to run my ionic app on an android device, and the command "ionic cordova run android --device" get as far as telling me an error occurred due to:
Requirements check failed for JDK 1.8.x! Detected version: 16.0.0
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.
So, after verifying which java versions I had and successfully changing the version to a 1.8.X, so when I run java -version, it returns:
java version "1.8.0_251"
However, running "ionic cordova run android --device" again, it returns the same original error:
Requirements check failed for JDK 1.8.x! Detected version: 16.0.0
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.
After some more research, I realized that the javac version of it, tells me another version, and it needs to be same I believe. So when I run "javac -version", I get:
javac 16
So... I couldn't figure out how to change the javac version to be the same as java, the only thing I figure is that it could be something with PATH, but the topics get a bit confusing as I'm not sure what to do next?
I have in my .zshrc file the following:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
Which I added to fix the original java version issue, but that didn't seem to have changed the javac as well.
So after running the commands "which java" and "which javac" respectively, I get:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
/usr/bin/javac
I assume there's something funny in here, huh? But this is basically where I'm stuck. I'm not even sure if this is the issue, but it's one of those things I think I'm just doing something stupid without realising it lol
Any help is greatly appreciated!
Goal
You are describing that you want "java" and "javac" to both resolve to JDK 1.8. From there, you'll be able to use ionic cordova to do things.
Starting point
Here are various commands you've run, along with their output (I changed format to make it look like actual commands being run, and the output):
Java compiler ("javac") is for JDK 16, and lives at /usr/bin/javac (which might be an alias to another location).
% javac -version
javac 16
% which javac
/usr/bin/javac
Java runtime – the thing which starts the Java Virtual Machine – is resolving somewhere else
altogether – /Library/Internet Plug-Ins/... – and shows up as version 1.8, not 16:
% which java
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
% java -version
java version "1.8.0_251"
A few takeaways..
You have JDK 16 installed, resolving to /usr/bin
You have something separately installed at "/Library/Internet.." – this is most likely a JRE (not a JDK), and is version 1.8
Fix
Install JDK 1.8 – this will give you a compiler and runtime that are both version 1.8
Follow download steps here: https://www.oracle.com/java/technologies/downloads/#java8 Once installed, you should be able to switch to using JDK 1.8, and confirm versions of both the compiler (javac) and the runtime (java) binaries.
There are various ways to set JAVA_HOME and manage multiple JDK installs – this is the simplest way to just get past the issue you're facing: set JAVA_HOME manually. This will be system dependent, but below is an example from my local system.
% export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_341.jdk/Contents/Home
Verify that "java" resolves to your new 1.8 install:
% java -version
java version "1.8.0_341"
Java(TM) SE Runtime Environment (build 1.8.0_341-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.341-b10, mixed mode)
Verify that "javac" also resolves to your new 1.8 install:
% javac -version
javac 1.8.0_341
If you see anything other than above, something else is going on, and we would need to see more details, including whatever output happened from following the above steps.

Not able to switch the Java version to Java 17

Posting again since someone moved my question a community where there is not much activity and the solution provided there in the comment did not work.
I have installed Amazon Corretto Java 17 from here.
However, I am not able to switch the Java version to Java 17.
Following are the steps I have already tried:
1.
export JAVA_HOME=$(`/usr/libexec/java_home -v17`)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home
I have also check the highest version of Java using below command:
/usr/libexec/java_home and it shows correct Java 17 version:
/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home
I have also checked all the versions of Java installed on my machine using command /usr/libexec/java_home -V and it correctly shows Java 8, 11, and 17:
17.0.1 (x86_64) "Amazon.com Inc." - "Amazon Corretto 17" /Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home
11.0.9.1 (x86_64) "Amazon.com Inc." - "Amazon Corretto 11" /Users/harsh.pamnani/Library/Java/JavaVirtualMachines/corretto-11.0.9.1/Contents/Home
1.8.0_275 (x86_64) "Amazon" - "Amazon Corretto 8" /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home
I also added JAVA_HOME exports mentioned in step-1 and step-2 to .zshrc and .bash_profile as well.
I have followed multiple questions on StackOverflow and multiple
blogs as well. For example,
How to set or change the default Java (JDK) version on macOS?
switch java version on mac OS
https://java.tutorials24x7.com/blog/how-to-switch-java-version-on-mac
https://www.lotharschulz.info/2019/08/21/mac-change-default-java-version
https://akrabat.com/using-jenv-to-select-java-version-on-macos/
https://www.happycoders.eu/java/how-to-switch-multiple-java-versions-windows/
I am using jenv to switch between different java versions. Even jenv is not able to find Java 17. I used jenv versions and following is the output:
system
1.8
1.8.0.275
11
11.0
* 11.0.9.1 (set by /Users/harsh.pamnani/.jenv/version)
corretto64-1.8.0.275
corretto64-11.0.9.1
I have also checked that JAVA_HOME is pointing to Java 17. Here is the screenshot: Screenshot
Even after following all the steps above when I do java --version, it is still set to Java 11:
openjdk 11.0.9.1 2020-11-04 LTS
OpenJDK Runtime Environment Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS, mixed mode)
I have also checked PATH variable, and nothing seems to be relatable to Java. Following is the output for path variables:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Users/harsh.pamnani/Downloads/apache-maven-3.6.3/bin
Could someone please help me understand if I am missing anything here. Thank you.
which java is often used to find the exact executable you are calling when you type in java.
Keep in mind that when you type in the command java your JAVA_HOME setting is not used. Rather, the operating system PATH setting is used. If you have an older copy of java "before" the one you want to use on the path, then that's what the operating system will give you. To fix a problem like this, you need to alter your path such that the directory of your desired java version comes before any other java versions.
I do see that you checked your PATH setting, but I think you didn't know what to check, because you only listed directories. In those directories, a java executable exists. If the old executable comes in a directory earlier in the path, that's the version of java you will get when running it from the command line, regardless of any other settings.
Now, it is still important to have the JAVA_HOME set correctly, because when various Java tools want to discover items, thy might read JAVA_HOME (and if it is wrong, get directed to a non-matching JVM).

Unable to open UIAutomatorviewer on Mac High Sierra

We have brand new MacBooks with High Sierra (10.13.6).
Other system info:
JAVA Version: java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
When tried to open Android UIAutomatorViwer we're getting following error:
/Library/Android/sdk/tools/bin/uiautomatorviewer ; exit;
/Library/Android/sdk/tools/lib is not supported. Use -classpath
instead. Error: Could not create the Java Virtual Machine. Error: A
fatal exception has occurred. Program will exit. logout Saving
session... ...copying shared history... ...saving history...truncating
history files... ...completed. Deleting expired sessions...111
completed.
More details:
Java is at: /usr/bin/java
Installed older java(8) JDK
Updated Java version to 1.8 in JAVA_HOME
Commands used to update Java Version:
cd ~/
vim ~/.bash_profile
Updated the JAVA_HOME
Save in vim using :wq!
source ~/.bash_profile
Restart & UiAutomatorViewer is working!
You need Java 8 for uiautomator as mentioned in this as well as other threads. But you can do this without updating the JAVA_HOME variable.
Update the java_exe path in the uiautomator.bat file using any editor.
For Windows systems, find the line
set java_exe=call ..\lib\find_java.bat
Update that to:
set java_exe=C:\Program Files\Java\jdk1.8.0_271\bin\java.exe
In this way, you don't need to update the JAVA_HOME variable which has a higher jdk version(useful for other programs).
If you really don't want to upgrade to Java 11.0 but still want to run then this may help.
uiautomatorviewer works fine with Java version 8. You need not downgrade java version to 1.8. Instead add this method to .bash_profile
uiautomator() {
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$ANDROID_HOME/tools
/Users/<username>/Library/Android/sdk/tools/bin/uiautomatorviewer
}
This would set the JAVA_HOME path to 1.8 and includes android platform and build tools to path variable.
Either,
Restart your terminal to get the changes reflected or
Compile your .bash_profile by . .bash_profile in the current terminal to get it reflected.
Start typing uiautomator in your terminal. It should work !
Work perfectly!
step 1: cd ~/
step 2: vim ~/.bash_profile
-Add text "export ANDROID_HOME ..." to end text.

Unable to find any jvms matching version 1.7 while starting neo4j

I am using Mac OS X Yosemite and I had Java8 JRE installed
but, when I start neo4j, it is unable to find any JVM's matching version 1.7
Neo4J startup script looks for JAVA_HOME and if it is not set defaults to setting it to Java v1.7. So, set your JAVA_HOME in your .bash_profile file.
export JAVA_HOME=$(/usr/libexec/java_home)
Then, either restart your Terminal or do
$ source .bash_profile
Now, if you restart Neo4J you shouldn't see the error message.
You've installed java 8 while neo4j is searching for java 7. So install java 7 and set it as your default jvm/jre and it should execute correctly.

JDK 7u10 and BlackBerry WebWorks SDK installation issues

For the past few days I have been trying to install the JDK 7u10 which is made available by Oracle. after installing this JDK, I then proceed to install BlackBerry WebWorks SDK but i keep getting he following error message: "JDK 1.6 or higher not installed" what could possibly be the reason for this?
Create enviroment variables JAVA_HOME & JAVA_PATH and point them to 32 bit version JDK bin folder.
on a cmd prompt type: set JA
check if the variables have the right values.
javac -version and java -version should give you the good version, 32 bit!.
check if the enviroment variable PATH has not the location of 64bit path, if it has, correct it,
On the file BlackBerryWebWorksSDK.exe don't forget to enable compatibility with Windows XP (sp3). if you are running win8 or 7
The problems was that JDK needs to be installed as 32-bit, even in a 64-bit architecture.Try this
Is JAVA_HOME properly set? Are you able to run "javac" from the command line? What version of java does "javac -version" report?

Categories

Resources