How to use ssl certificates in Java on a Mac - java

I found this question: Import Windows certificates to Java, which had the answer for a Windows machine. I have been unable to find the equivalent to -Djavax.net.ssl.trustStoreType=WINDOWS-ROOT for MacOS.

On OSX you can set -Djavax.net.ssl.trustStoreType=KeychainStore to use the OSX keychain for trusted certificates; which is part of the Apple JCA Provider.

Jacob Blanton provided the solution in his comment, above. By adding -Djavax.net.ssl.trustStore=<path to cacerts> to MAVEN_OPTS in my .bash_profile, both standalone Maven and Maven in Eclipse were able to access the repo as needed [after I installed the cert to cacerts using the instructions Jorge Campos linked to in his comment, found here https://blog.alwold.com/2011/06/30/how-to-trust-a-certificate-in-java-on-mac-os-x/ ]

I am using version 10.14.1 (Mojave).
The path java in my case was:
"/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home"
In my ~/.bash_profile I put this line:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home"
after that I typed source ˜/.bash_profile
type echo echo $JAVA_HOME
Check the configuration typing $JAVA_HOME/bin/java -version
You should see something like that:
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

Related

How to Execute OpenJDK Debugging Package

I need OpenJDK's build that provides symbols for debugging in RedHat Linux Server 8.2. I had installed OpenJDK 1.8.0 252-* (latest) with:
yum install java-1.8.0-openjdk-devel
However, afterward I realize that I need a package that has been built with debugging enabled and also I was interested in a very specific version (242-*), so I downloaded it directly from RedHat Acces site (this link).
After installing it with rpm (rpm -ivh java-1.8.0.....), and chmoding everything to 774, when I navigate to java directories, I don't seem to be able to execute java (or in this case java.debug):
[root#localhost lib]# /usr/lib/debug/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b07-1.el6_10.x86_64-debug/bin/javac.debug -version
-bash: /usr/lib/debug/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b07-1.el6_10.x86_64-debug/bin/javac.debug: No such file or directory
[root#localhost lib]# /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el8_1.x86_64/bin/java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
Am I missing something?
java-1.8.0-openjdk-debuginfo is a complementary package that provides debug symbols for OpenJDK binaries. This package is not self-sufficient; it does not contain executable binaries.
In order to use OpenJDK with debug symbols, you need to install both java-1.8.0-openjdk and the corresponding java-1.8.0-openjdk-debuginfo package of the same version.

How to set bash path for both java and python

I have just installed OpenJDK8 latest version in and changed my default java_home and version in bash, but why the system still shows that I am in openjdk version "1.8.0_152-release"? I don't even know when I installed the 1.8.0_152-release version.
Yilins-Macbook-Pro:~$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_232, x86_64: "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
Yilins-Macbook-Pro:~$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
Yilins-Macbook-Pro:~$ java -version
openjdk version "1.8.0_152-release"
OpenJDK Runtime Environment (build 1.8.0_152-release-1056-b12)
OpenJDK 64-Bit Server VM (build 25.152-b12, mixed mode)
Update: OK here is the problem. My original path is set to anaconda thus the java version is the one under anaconda.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
# export PATH="/Users/liyilin/anaconda3/bin:$PATH"
But here is another issue regarding path. If I changed the path for JAVA_HOME, my original path for python is no longer useful. Is there a way to make them both exists when operating? Otherwise I need to keep changing back and forth when writing java and python.
You need to put both things in your path
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
export ANACONDA_HOME="/Users/liyilin/anaconda3"
export PATH="${JAVA_HOME}/bin:${ANACONDA_HOME}/bin:$PATH"
Also, I would suggest using SDKman for Java things and pyenv for python... Both will update your PATH for you and allow you to easily upgrade versions. For example, you should switch to at least Java 11
Homebrew is another option
Run source .bash_profile to take the changes on .bash_profile to take effect.
Delete the previous version or remove the previous version path from environmental path .

How to use different java version by alias?

I have some tools that can only be run by java 8. So i downloaded java 8, but now i have two versions of java installed at the same time (os : Ubuntu):
java-1.11.0-openjdk-amd64 1101 /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
My question is: is it possible to call these both versions by different aliases? For example i type:
"java" to call java 11 (the default) and
"java8" to call java 8
You could do it in a couple of ways. The easiest way would be to put the following 2 lines in your profile initialization file:
alias java='/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java'
alias java8='/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java'
Other ways are depending on whether you are the admin of the machine or not. You can create soft links like this:
/usr/bin/java -> /usr/lib/jvm/java-1.11.0-openjdk-amd64
(Not recommended since certain tools in your system may depend on /usr/bin/java).
Update: Try to use sdkman if you can. Makes the job of installing java versions and setting up JAVA_HOME env variable simple.
You can do this as well for JAVA_HOME:
alias java8="export JAVA_HOME=`/usr/libexec/java_home -v 1.8`"
alias java11="export JAVA_HOME=`/usr/libexec/java_home -v 11`"
Updated:
To run java directly use:
$ alias java8="`/usr/libexec/java_home -v 1.8`/bin/java"
$ alias java11="`/usr/libexec/java_home -v 11`/bin/java"
$ java8 -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)
$ java11 -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
You can hardcode your path as well.
I have some tools that can only be run by java 8. So I downloaded java 8, but now I have two versions of java installed at the same time (os : Ubuntu).
You could do this using aliases (see other answers) but this has the problem that only a shell will respect an alias ... and then only if it has the alias defined or loaded by the shell:
Aliases are not inherited via the environment.
Whether a tool's launch script will see the aliases will typically depend on whether you put the alias definitions into the correct shell init file.
It is also possible that an application's launch script will assume that java8 or java11 is a genuine (absolute or relative) pathname, and try to resolve it via the file system.
In short, there is a good chance that using an alias won't work in your use-case.
So a better idea is to arrange that the appropriate Java is on the Command Search Path. You could do this a number of different ways:
You could use the Ubuntu "alternatives" system to globally switch between Java 8 and Java 11.
You could update the PATH variable so that (for example) the Java 11 executables come before the Java 8 executables. This could be done in shell init files (per user or globally), in the application launch scripts ... or by hand.
You could even replace "/usr/bin/java" or whatever with a direct symlink to the version you want to use. (This is crude, and I wouldn't recommend it.) Note that the Java command entries in "/usr/bin" are probably already symlinks.)

Need help installing Java 8 on Mac OS X

I am trying to upgrade to: Java 8 Update 66, from Java 6, on my Mac running Mac OS X 10.10.5. I downloaded the Java Update .dmg file: re-8u66-macosx-x64.dmg. When I run the installer I get the message it installed properly. When I confirmed the install via the FireFox Browser at this URL:
https://java.com/en/download/installed.jsp
It reports:
Congratulations!
You have the recommended Java installed (Version 8 Update 66).
However, If I open a terminal window and enter: java -version
It reports:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
Can someone please explain what is going on here? Do I need to update a link somewhere?
Thanks.
Please check your PATH variable, and make sure that the java directories in the path match the directories in your computer. It should be the bin folder of the JAVA_HOME environment directory. Also check that JAVA_HOME environment variable is set to the jdk folder of your java installation.
There's two option based on my experience to fix this issue, fisrt uninstalled the java on your computer and reinstalled using the latest version.
Second, run a different version of Java, either specify the full path, or use the java_home tool:
List your installed java version:
$ /usr/libexec/java_home -V
In this case you are using java 8 so you can run command
$ /usr/libexec/java_home -v 1.8 --exec javac -version
If you want to make easy to switch your java version you can create alias in ~/.bashrc
alias java6="export JAVA_HOME=$(/usr/libexec/java_home -v 1.6);echo 'using Java 6'"
alias java8="export JAVA_HOME=$(/usr/libexec/java_home -v 1.8);echo 'using Java 8'"
Hope it help

How I can play with EC2 API tools?

I'm getting the error to run the script "ec2-describe-regions"
$ec2-describe-regions
/usr/local/ec2/ec2-api-tools-1.6.14.1/bin/ec2-cmd: line 62: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java/bin/java: Not a directory
Before it, I did followings:
Open a terminal on my personal computer.
Install Java.
Create security credentials (an X.509 certificate and private key).
Set up a few environment variables.
Run my first command.
Here is the information I did:
$which java
/usr/bin/java
$echo $EC2_HOME
/usr/local/ec2/ec2-api-tools-1.6.14.1
$echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
$java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
Try the following:
mv /usr/bin/java /usr/bin/java.orig
ln -s /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java /usr/bin/java
You may have two or more java instances on your server. Make sure you use the same java executable where your JAVA_HOME points to.
This command uses the old CLI tools, i'd recommend you use the new, unified and greatly improved CLI:
https://aws.amazon.com/cli/

Categories