Search code examples
javasslsni

Cannot find SNIServerName class


I am working with SSL connections using javax.net.ssl.HttpsURLConnection. I upgraded from java 1.7 to java 1.8. I need to set SNI host names in SSLParameters using javax.net.ssl.SSLParameters.setServerNames(List<SNIServerName> serverNames). But the compiler cannot resolve the class SNIServerName. The compiler displays this error:

unable to resolve class javax.net.ssl.SNIServerName

My java version:

java version "1.8.0_121" Java(TM) SE Runtime
Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM
(build 25.121-b13, mixed mode)

How do I import SNIServerName or SNIHostName? AFAIK they have been introduced in Java 8. Is there an issue with my java version?


Solution

  • Just make sure that your JAVA_HOME is correctly configured. Just follow the steps mentioned below

    vim ~/.bashrc
    JAVA_HOME = <path to your java8 bin>
    PATH = $JAVA_HOME:$PATH
    save this and then
    source ~/.bashrc
    

    after this just verify by $JAVA_HOME on your terminal.