How to downgrade JDK/javac - MacOS - macos

I am trying to downgrade the jdk for a project I'm running from 17.0.5 to 1.8, but have not been able to replicate any of the results I've found online. Specs and attempts below.
Specs:
MacOS Big Sur v11.6.8
Java v1.8.0_351
Javac v17.0.5
Gradle v7.6
Homebrew v3.6.16
Running /usr/libexec/java_home -V:
Matching Java Virtual Machines (4):
17.0.5 (x86_64) "Oracle Corporation" - "Java SE 17.0.5" /Library/Java/JavaVirtualMachines/jdk-17.0.5.jdk/Contents/Home
1.8.351.10 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_351 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home
1.8.0_341 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_341.jdk/Contents/Home
First, I tried replicating the code from this answer regarding downgrading java:
https://stackoverflow.com/a/48422257/20834861
I quickly realized that the bash profile from sudo nano was already used to downgrade java to v1.8.
Then, I tried this solution: https://stackoverflow.com/a/23819062/20834861
But sudo mv jdk1.8.0_351.jdk ~/Desktop/ returns the following error: mv: rename jdk1.8.0_351.jdk to /Users/sahil/Desktop/jdk1.8.0_351.jdk: No such file or directory
So next, I tried the solution from this link:
https://mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/#java-home-and-macos-11-big-sur
When I tried the final line of code, echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home , I received the following error: zsh: permission denied: /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home .
Finally, I tried a similar line of code but with source as the bash_file instead of zshenv. I got the same error.
I must be missing something really obvious but I could not find anything else on the internet. Any help is appreciated.

With OSX you can select which jdk to use by using the JAVA_HOME environment variable. To set it.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home
That should work because it is in the list of jdk's you have available according to java_home. You can also use the java_home command to get the appropriate jdk.
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Then when you run java or javac it should be from the version selected.

Related

How to get Kotlinc 1.8.0 to run with Ubuntu on Windows

I installed Kotlinc through the zip file kotlin-compiler-1.8.0.zip and extracted it and moved the kotlinc\bin files to my C:\Program files. I later then verified that I had installed it correctly by running the kotlinc -version command in the terminal and got back info: kotlinc-jvm 1.5.21 (JRE 16.0.2+7-67). So I believe I have that working just fine. So I believe now the error is arising from Java somehow.
When I go to run my simple hello world program with this:
kotlinc main.kt -include-runtime -d main.jar
I am met with the error:
/mnt/c/Program Files/kotlinc/bin/kotlinc: line 98: java: command not found
Previously I was just getting: kotlinc command not found. I later read on StackOverflow someone else was having the same problem and the answer to that solution was just add it to the environment Variable path, in which I did but I very soon then ran into this issue.
I have since tried everything I have came across on this issue, I've reinstalled the kotlinc compiler and java and put the Java\jdk16.0.2\bin in my environment variable path as well. When I try to run the simple command kotlinc help in Ubuntu I am also met with the same line 98: java command not found error.

sdkman installed grails 4.0.4, now grails is broken and wont start

I have some older version of grails installed (3.3.8), and tried to use sdkman to install a newer version (4.0.4). The install worked, but grails is now completely broken. i also updated java to 14 from the dmg from the oracle website. Basically grails is now completely broken. Any ideas how to fix?
mac 10.14.4
$ sdk version
SDKMAN 5.7.3+337
$ sdk current java
Not using any version of java
$ java -version
java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
$ sdk current
Using:
groovy: 2.5.8
$ grails --version
| Grails Version: 3.3.8
| Groovy Version: 2.4.15
| JVM Version: 14.0.2
$ sdk install grails
Downloading: grails 4.0.4
In progress...
######################################################################## 100.0%
Installing: grails 4.0.4
Done installing!
Setting grails 4.0.4 as default.
$ sdk current
Using:
groovy: 2.5.8
$ grails --version
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:107)
at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95)
at org.codehaus.groovy.reflection.ReflectionCache.<clinit>(ReflectionCache.java:39)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:209)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:107)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:86)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.bitwiseNegate(ScriptBytecodeAdapter.java:842)
at org.grails.config.NavigableMap.<clinit>(NavigableMap.groovy)
at org.grails.cli.GrailsCli.<clinit>(GrailsCli.groovy:77)
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
at org.codehaus.groovy.runtime.dgmimpl.NumberNumberMetaMethod.<clinit>(NumberNumberMetaMethod.java:33)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:124)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:346)
at java.base/java.lang.Class.newInstance(Class.java:604)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.createMetaMethodFromClass(MetaClassRegistryImpl.java:257)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:110)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:86)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.bitwiseNegate(ScriptBytecodeAdapter.java:842)
at org.grails.config.NavigableMap.<clinit>(NavigableMap.groovy)
at org.grails.cli.GrailsCli.<clinit>(GrailsCli.groovy:77)
I dont see an easy way to uninstall java 14, or go back in time.
echo $PATH
/Users/xx/.sdkman/candidates/groovy/current/bin:/Users/xx/.sdkman/candidates/grails/current/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Appz/apache-jmeter-5.3/bin:/usr/local/go/bin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/xx/go/bin:/Users/xx/dev/grails-3.3.8/bin:/Users/xx/dev/flutter/bin:/Users/xx/dev/gradle-5.1.1/bin:/appz/cassandra/bin
I am guessing I can try to hack the path etc, to fix.
This is my current .bash_profile:
vi .bash_profile
export JAVA_HOME=`/usr/libexec/java_home`
export GRAILS_HOME=/Users/xx/dev/grails-3.3.8
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
export PATH=$PATH:$GRAILS_HOME/bin
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
export GRADLE_HOME=/Users/xx/dev/gradle-5.1.1
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
PATH="${PATH}:/Users/xx/dev/flutter/bin"
PATH=$PATH:$GRADLE_HOME/bin
# Cassandra
if [ -d "/appz/cassandra" ]; then
export PATH="$PATH:/appz/cassandra/bin"
fi
export PATH
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="/Users/simonh/.sdkman"
[[ -s "/Users/xx/.sdkman/xx/sdkman-init.sh" ]] && source "/Users/xx/.sdkman/bin/sdkman-init.sh"
~
This is odd, why is grails home still 3.3.8, when sdkman installed and made 4.0.4 current? Why didnt it edit the path? What version should I set gradle to? How do I go back to java 8, as I think there are bugs in java 14 which is causing issues with grails?
OK, figured it out.
First, I had to manually fix the java version.
To do this go to
$ /usr/libexec
$ ./java_home -V
This outputs one or more versions:
14.0.2, x86_64: "Java SE 14.0.2" /Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home
1.8.0_131, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
Now edit our .bash_profile and replace the JAVA_HOME line with the version you want, either the whole thing (1.8.0_131) or just the major (1.8) thusly:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
Now when you open a new window, and do "java -version" you get 1.8, and when you do "grails -version" I finally get 4.0.4.
Yay!
The strange part is that just changing JAVA_HOME should not affect whats on the path, but it seems to. i.e. just setting JAVA_HOME should not affect what version of java is run when I type in "java", but it does. i.e. there is no line suchy as "PATH=$PATH:$JAVA_HOME/bin in muy bash_profile.

Oracle Instant Client still not working on Mac OS Catalina 10.15.4

I installed the Oracle Instant Client version 19.3 on my Mac Os Catalina version 10.15.4
But i still have the same error on python3.7 and python3.8:
Origin: (cx_Oracle.DatabaseError) DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): no suitable image found. Did find:
file system relative paths not allowed in hardened programs". See https://oracle.github.io/odpi/doc/installation.html#macos for help
(Background on this error at: http://sqlalche.me/e/4xp6)
here is my installation:
$: ls-l ~/lib
ls -l ~/lib
total 0
lrwxr-xr-x 1 giacomocallegaro staff 58 22 Apr 09:13 libclntsh.dylib -> /Users/giacomocallegaro/instantclient_19_3/libclntsh.dylib
$: cat .zprofile
Setting PATH for Python 3.8
The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH
Setting PATH for Python 3.7
The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH=$PATH:~/instantclient_19_3
export PATH
$: echo $PATH
/Users/giacomocallegaro/.nvm/versions/node/v12.14.1/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/giacomocallegaro/.nvm/versions/node/v12.16.1/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/opt/openssl/bin:/Users/giacomocallegaro/instantclient_19_3:/Users/giacomocallegaro/instantclient_19_3
$: which python:
/usr/bin/python
when I run sqlplus:
$: sqlplus -v
SQL*Plus: Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
Can some one help me please?
Go to https://www.oracle.com/technical-resources/
Downloads --> Oracle Instant Client --> macOS(Intel x86) --> Basic Package
In your download folder you will find a folder named instantclient_19_3
Add the following to your python script
import cx_Oracle
cx_Oracle.init_oracle_client(lib_dir=r'/Users/<username>/Downloads/instantclient_19_3')
Some windows will pop up, so go to System preferences --> Security & Privacy --> General and there you will see a notification. Click on open anyway. You will have to repeat this last step 3-4 times.
After you download instant client from here, create a symbolic link into /usr/local/lib folder (that's where all .dylib files keep their symbolic links).
In my case, I extracted instant client into /opt/oracle/instantclient_19_3. So the command is:
$ ln -s /opt/oracle/instantclient_19_3/libclntsh.dylib /usr/local/lib/
However, there is another problem when I try to create the connection from python:
Error while trying to retrieve text for error ORA-01804
Oracle says: "Instant Client 19.3 and 18.1 support macOS Mojave and High Sierra", and I have macOS Catalina 10.15, don't know if this has anything to do with that, error 01804 says that timezone information is invalid.
More info on this: http://www.dba-oracle.com/t_ora_01804_start_oracle.htm
EDIT: issue resolved.
After downloading the SQL*Plus Package I managed to connect and verify the instant client works. My python issue was also resolved when I restarted IntelliJ (I was running the server from within so the PATH might have not been updated).
Maybe the error is misleading and it is related to general issue with Oracle Instant Client on MacOS Catalina? Have a look at this blog post:
Gary's Oracle On Tap
Hope this helps!

installing java ee 7 on a brand new mac book air

I managed to install JDK 7 thanks to it being a dmg file, but I'm having problems installing Java EE 7... I have registered JAVA_HOME on launchd.conf but its still not finding it... here's the error:
sudo sh ./java_ee_sdk-7-unix.sh
Extracting the installer archive...
java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:193)
at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:139)
at sun.tools.jar.Main.extractFile(Main.java:961)
at sun.tools.jar.Main.extract(Main.java:877)
at sun.tools.jar.Main.run(Main.java:263)
at sun.tools.jar.Main.main(Main.java:1177)
Extracting the installer runtime...
Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java...
Extracting the installer resources...
Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java...
Extracting the installer metadata...
Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java...
java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:193)
at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:139)
at sun.tools.jar.Main.extractFile(Main.java:961)
at sun.tools.jar.Main.extract(Main.java:877)
at sun.tools.jar.Main.run(Main.java:263)
at sun.tools.jar.Main.main(Main.java:1177)
chmod: product-installer.sh: No such file or directory
sh: product-installer.sh: No such file or directory
and here's what happens when i echo JAVA_HOME:
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home
java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
Any help? I'm kinda new to mac

maven error when running in cygwin?

I have cygwin in Windows 7 and downloaded and installed maven "binaries" and have the following set
export JAVA_HOME=/cygdrive/c/java/jdk1.7.0_11
export MAVEN_HOME=/usr/apache-maven-3.0.5
export M2_HOME=/home/MyUser/.m2
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
$ which java
/cygdrive/c/java/jdk1.7.0_11/bin/java
$ java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
$ which mvn
/usr/apache-maven-3.0.5/bin/mvn
$ mvn -version
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
I've looked at Maven error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher but it did not address my issue.
What did I miss?
Maven with Cygwin - Error: JAVA_HOME is not defined correctly
The "alias mvn=mvn.bat" answer toward the bottom of above post worked for me. However, is this THE solution?
I spent a couple of hours fruitlessly fiddling with different combinations of JAVA_HOME, M2_HOME and M2 after this same problem. Finally I set down to debugging the mvn script (by changing line 1 to read "#!/bin/sh -x"). It occurs because the script is relying on shell globbing to get the correct version of the .jar file (at approx. line 157):
CLASSPATH="${M2_HOME}/boot/plexus-classworlds-*.jar"
the * is not being expanded, for some reason globbing is disabled;
Hence the command the script attempts to execute is:
'/cygdrive/c/Program Files/Java/jdk1.7.0_40/bin/java' -classpath 'D:\apps\apache-maven-3.0.4\boot\plexus-classworlds-*.jar' '-Dclassworlds.conf=D:\apps\apache-maven-3.0.4\bin\m2.conf' '-Dmaven.home=D:\apps\apache-maven-3.0.4' org.codehaus.plexus.classworlds.launcher.Launcher -version
when it should be:
'/cygdrive/c/Program Files/Java/jdk1.7.0_40/bin/java' -classpath 'D:\apps\apache-maven-3.0.4\boot\plexus-classworlds-2.4.jar' '-Dclassworlds.conf=D:\apps\apache-maven-3.0.4\bin\m2.conf' '-Dmaven.home=D:\apps\apache-maven-3.0.4' org.codehaus.plexus.classworlds.launcher.Launcher -version
Solution: Edit the "mvn" script and change line 157 to read:
CLASSPATH="$(echo ${M2_HOME}/boot/plexus-classworlds-*.jar)"
change the JAVA_HOME path in .bashrc_profile file

Resources