Please use below command :-
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_261`
Answer from Madhurish Gupta on Stack Overflowchange java version in macOS BigSur - Stack Overflow
Java enterprise development on MacOS Big Sur
Nothing strange so far.. everything you listed works as before on my one-day-of-work.
More on reddit.commacos - Java works not well after upgrage Mac OS to Big Sur(v11.0.1) - Stack Overflow
java - Wrong JAVA_HOME after upgrade to macOS Big Sur v11.0.1 - Stack Overflow
Videos
Please use below command :-
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_261`
you have to unset JAVA_HOME and set JAVA_VERSION then it works.
~% JAVA_VERSION=12 java -version
openjdk version "14.0.2" 2020-07-14
~% export JAVA_VERSION=12
~% java -version
openjdk version "14.0.2" 2020-07-14
~% unset JAVA_HOME
~% java -version
java version "12.0.1" 2019-04-16
~% JAVA_VERSION=13 java -version
java version "13-ea" 2019-09-17
or if you need to set JAVA_HOME you need to unset before calling /usr/libexec/java_home
function jav {
unset JAVA_HOME
export JAVA_HOME=`/usr/libexec/java_home -v $@`
}
~% jav 12
~% java -version
java version "12.0.1" 2019-04-16
~% jav 13
~% java -version
java version "13-ea" 2019-09-17
Hello guys! Has anyone updated?
How's it everything working on MacOS update Big Sur as enterprise developer?
Are there any problems, issues present?
Interested in working of such stack:
-
Docker
-
Java 8/11/etc.
-
Intellij Idea
-
etc...?
Being newB around here, so sry if have chosen mistaken thread or something.
Reason: In ~/.bash_profile, JAVA_HOME= $(/usr/libexec/java_home), after upgraded, $(/usr/libexec/java_home) link to /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java which doesn't exist in my disk, so jdk is missing.
Solution: I delete jdk in /Library/Java/JavaVirtualMachines and reinstall jdk8, and then set JAVA_HOME as:
/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
instead of soft link and source ~/.bash_profile to let it work.
My full settings:
kevinMacBook-Pro:bin kevin$ cat ~/.bash_profile
export M2_HOME=/usr/local/apache-maven-3.6.3
#Mac OSX 10.5 or later version need this configure
#export JAVA_HOME=$(/usr/libexec/java_home)
#Mac 11 need this configure
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
export MySQL_HOME=/usr/local/mysql
Now, jdk works, after mac os upgraded, it indeed update the soft link of $(/usr/libexec/java_home) and link to a not existed link, so i think you don't need to delete your jdk, just update env variables and re-open terminal to check if jdk reset correctly.
Find you JDK location (mine was /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home).
- In terminal
vim ~/.bash_profile(resp. edit the file in any way you're used to) - Add a line exporting your JDK location (in my case it was
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home) - In terminal
source ~/.bash_profile - In terminal
echo $JAVA_HOMEto make sure the environment variable is set properly
I have Big Sur 11.2.1 from 18.02.2021. I had the same issue with JAVA_HOME path configuration. After reading a lot of information I solved my problem with next:
Install JDK 8: https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html Java SE Development Kit 8u281
Install it as usual on your MacOS Big Sur.
Check JDK version:
java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)
Check what versions of JDK are already installed on your machine:
/usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.281.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_281 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Get only one that you need:
/usr/libexec/java_home -v 1.8.0_281
/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
On Catalina and Big Sur - there is Z-shell , to add Environment variables like JAVA_HOME there are two files for that: ~/.zshenv and ~/.zshrc, I couldn't make it work with first one. It worked for me like this:
nano ~/.zshrc
Add to that file this line:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0_281)
Press Ctrl+X and save changes.
Then run command to apply that changes to current terminal:
source ~/.zshrc
After that you can check if everything is working with command:
echo $JAVA_HOME
it will print you: /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
Restart your terminal and programs which will be using JAVA_HOME variable. For me it was Android Studio. Now everything works fine. I am new to Mac OS and it took me with 4hours to solve this. With Windows it's just done in a minute:)
Seems in macOS Big Sur v11.0.1 the behavior of the /usr/libexec/java_home -v ... command has changed: it is sensitive to the previously set value of JAVA_HOME environment variable.
Exact behavior is not clear, I couldn't find any documentation on this, but in my experiments it reported the version already set in JAVA_HOME, regardless of the -v switch:
% JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home /usr/libexec/java_home -v 1.8.0_162
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
Additionally, I noticed that it reports nothing, if JAVA_HOME is set, but doesn't point to a valid java home (also for -V):
% JAVA_HOME=dummy /usr/libexec/java_home -v 1.7.0_45
% JAVA_HOME=dummy /usr/libexec/java_home -V
%
Solution is to ensure JAVA_HOME is not set before executing /usr/libexec/java_home:
% unset JAVA_HOME ; /usr/libexec/java_home -v 1.8.0_162
/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
Can confirm this is still happening on adoptopenjdk14, as well as openjdk early access build for j16.
You can file a bug if you want, but I bet it'll be denied. At this point, the name Mac OS X is not so much 'the name of the OS' as a 'globally agreed upon keyword identifying that unix-based mac operating system', where I mean globally literally (as in, 'around the planet', not 'across your source base/VM'). Changing it would just break stuff needlessly. The same applies, to a lesser degree, to version 10.16: The thing before the dot is not so much 'this is how the OS identifies itself' and more a 'globally agreed upon versioning scheme for Mac OS, identifying a wide and ill defined set of capabilities'.
There is no meaningful difference between the transition between big sur and catalina, other than the fact that apple made a marketing decision. If you want to point at an OS transition that might warrant the entirely nebulous choice to consider it a 'major change', surely it was the one to catalina, as that made by far the largest changes (including removing support for 32-bit entirely) in the last bunch of releases.
This leaves you with the challenge of: Okay, great, I can use System.getProperty("os.name") to get the globally agreed upon keyword that means unix-like Mac OS, and os.version for a string I can break into bits to figure out some nebulous batch of capabilities, but what if I need the actual name of the OS to e.g. show to a user?
Then you have three major options:
The easy one is to just write mapping code. Acknowledge that
os.nameandos.versiongive you (rather arguably) useful intent and not so much official names, and therefore, write some mappings. These would map name/version pairs to rendering strings, falling back to just printing the name string and the version string, concatenated, verbatim. You could add a mapping:Mac OS X/10.16→Mac OS Big Surin this table.The hard way: Figure out you're on a mac (which is now easier;
os.namereturnsMac OS X, or just check for the existence:Files.isExecutable(Paths.get("/usr/bin/sw_vers"))), and then useProcessBuilderto execute/usr/bin/sw_vers, picking up all output into a big string, and then parse it. Its output looks like:
ProductName: macOS
ProductVersion: 11.1
BuildVersion: 20C69
which, crucially, doesn't even include the words Big Sur, but does give you 11.1. I don't know how to run a command line tool that actually gives you Big Sur. Maybe system_profiler, but note that this takes many minutes to run, I really doubt you want to run that.
NB: you can also run .command("/usr/bin/sw_vers", "-productVersion") which gives you just 11.1, this may be a lot simpler to parse. -productName also works, gives you just macOS.
- If you need this information to scan for OS capabilities, then stop doing this. It doesn't work with browsers, and it's not a good plan for OS releases either. What capability are you scanning for? Imagine, for example, if it is 'Can I run /usr/bin/sw_vers to figure stuff out', as a hypothetical example. The right strategy is NOT to check os.name/os.version, conclude that the command must exist, and then run it, failing catastrophically if it is not there. The right move is to check if /usr/bin/sw_vers exists, and then execute it, falling back to some non-mac based solution (perhaps /usr/bin/uname) in other cases. Scan for the capability, don't scan for the OS/version.
Java code to call native tool sw_vers
Regarding Option # 2 in the Answer by rzwitserloot, here is a complete code example to run from Java a command-line tool sw_vers that describes the version of macOS software running on the host computer.
If on the command-line (console) such as in Terminal.app, you run:
sw_vers
…in Big Sur on an Intel Mac we get:
ProductName: macOS
ProductVersion: 11.2
BuildVersion: 20D64
We only need the middle piece. So running:
sw_vers -productVersion
…shows simply 11.2, the value we need for your purpose.
Here is complete example app with a method to return this string into Java.
ProcessBuilder class creates operating system processes. Each new process is represented by the Process class.
We use try-with-resources syntax to automatically close the InputStream and Scanner objects.
Once you have the 11.2 string in hand, split on the FULL STOP, pull the first number 11, and you know you are running on Big Sur.
package org.example;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
/**
* Example code showing how to get current version of macOS from Java
* by running a native command-line tool `sw_vers`.
*/
public class App
{
public static void main ( String[] args )
{
App app = new App();
app.demo();
}
private void demo ( )
{
String version = this.getMacOsVersionNumber();
System.out.println( "version = " + version );
}
public String getMacOsVersionNumber ( )
{
String result = "";
List < String > command = List.of( "sw_vers" , " -productVersion" );
try (
InputStream inputStream = new ProcessBuilder( command ).start().getInputStream() ;
Scanner s = new Scanner( inputStream ).useDelimiter( "\\A" ) ;
)
{
result = s.hasNext() ? s.next() : "";
}
catch ( IOException e )
{
e.printStackTrace();
}
return Objects.requireNonNull( result );
}
}
I updated to big Sur yesterday and when I try programming in java on vs code everything is throwing an error literally every line. some of my code that was working completely fine before I updated will not compile now. Please help I have a Java test Monday and I need to figure this out.