Tagged: jdk

selecting javac with maven in command line


I just found that some of my company’s legacy codes doesn’t compile with JDK 8. And I just tried selecting the javac executable in command line rather than changing maven-compiler-plugin‘s configuration.

$ mvn -Dmaven.compiler.fork=true -Dmaven.compiler.executable=/path/to/jdk7/javac clean package

Note that, as documented, maven.compiler.fork parameter must be true.

Installing the StartCom CA Certificate into the local JDK


references

problem

I just found that my local JDK doesn’t like the StartSSL™‘s certificate on remote server.
He kept failing with following error while deploying site.

# Transfer error: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

solution

Download Tool Box/StartCom CA Certificates/StartCom Root CA (PEM encoded) which is named ‘ca.pem’.
Then execute following script.

KEYSTORE=$JAVA_HOME/jre/lib/security/cacerts
$JAVA_HOME/bin/keytool -import \
  -alias StartCom-Root-CA \
  -file ca.pem \
  -keystore "$KEYSTORE"

When asked for password? changeit.

installing latest oracle jdk in old ubuntu


add the repository

$ sudo add-apt-repository ppa:webupd8team/java

when

sudo: add-apt-repository: command not found

then

$ sudo apt-get install python-software-properties

update

$ sudo apt-get update

install

$ sudo apt-get install oracle-java7-installer
$ sudo apt-get install oracle-java8-installer

switch

$ ls -1F /usr/lib/jvm/
java-7-oracle/
java-8-oracle/

$ update-java-alternatives -l
java-7-oracle ...
java-8-oracle ...

$ sudo update-java-alternatives -s java-7-oracle
$ java -version
java version "1.7.x_yy"
...

$ sudo update-java-alternatives -s java-8-oracle
$ java -version
java version "1.8.x_yy"
...
$

switch along java_home

$ cat java7
#!/bin/sh
alternative=java-7-oracle
sudo update-java-alternatives -s $alternative
export JAVA_HOME=/usr/lib/jvm/$alternative

$ cat java8
#!/bin/sh
alternative=java-7-oracle
sudo update-java-alternatives -s $alternative
export JAVA_HOME=/usr/lib/jvm/$alternative

$ . java7;javac -version;echo $JAVA_HOME
javac 1.7.x_yy
/usr/lib/jvm/java-7-oracle

$ . java8;javac -version;echo $JAVA_HOME
javac 1.8.x_yy
/usr/lib/jvm/java-8-oracle

if you want to remove the repository

$ sudo add-apt-repository ppa:webupd8team/java --remove

interesting…

export JAVA_HOME=$(dirname $(dirname $(readlink -e /usr/bin/javac)))
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")