5

I have been using the following to download JDK 8u112 via a script.

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz

Recently, it throws ERROR 404: Not found and when you go to the link, it shows the same text in Downloading Java JDK on Linux via wget is shown license page instead

I've also tried http://download.oracle.com/otn/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz but it throws 401 Authorization Error.

Is there a new work around on this?

TGKL
  • 312
  • 1
  • 14
  • Possible duplicate of [Installing JDK on Linux](https://stackoverflow.com/questions/22786468/installing-jdk-on-linux) – Stremovskyy Sep 27 '18 at 10:06

2 Answers2

0

It seems like the most recent version of jdk can be downloaded by wget but not the files in the archives. As such, I'm using casper.js script to login to Oracle and to download.

Following is my script to download Japanese version of jdk8u121. The current script will only attempt to download but will fail on redirect. I'm using download.sh bash script to scan the log to get the url with session parameter and using wget to do the actual download.

You'll need to replace <username> and <password> with valid ones to login to Oracle site.

Change values of jdkTag and jdkFileLink to get the jdk version you want to download.

oraclejdk.js

var casper = require('casper').create({
  verbose: true,
  logLevel: 'info',  // debug
  pageSettings: {
    userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36",
    loadImages: false,
    loadPlugins: false
  }
});

// login info
var loginUrl='http://www.oracle.com/webapps/redirect/signon?nexturl=https://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html';
var username='<username>';
var password='<password>';

// accept license page info
var jdkUrl='http://www.oracle.com/technetwork/';
var jdkTag='jdk-8u121-oth-JPR';

// download jdk info
var jdkFileLink='jdk-8u121-oth-JPRXXXjdk-8u121-linux-x64.tar.gz';

// open login page
casper.start(loginUrl);

casper.thenEvaluate(function(username, password) {
//  this.capture('loginPage.png', {top:0, left:0, width:600, height:800});
    document.querySelector("#sso_username").value = username;
    document.querySelector("#ssopassword").value = password;
    doLogin(document.LoginForm);
}, {
     username: username,
     password: password
});

// login to oracle site
casper.then(function() {
  this.waitForUrl(jdkUrl, function() {
//    this.capture('jdkPage.png', {top:0, left:0, width:1200, height:800});
    this.evaluate(function(jdkTag) {
      disableDownloadAnchors(document, false, jdkTag);
      hideAgreementDiv(document, jdkTag);
      writeSessionCookie('oraclelicense', 'accept-securebackup-cookie');
    }, {
        jdkTag: jdkTag
    });
  }, null, null, 5000);
});

// accept license
casper.then(function() {
  this.waitFor(function checkLink() {
    return this.evaluate(function(jdkTag) {
      return (document.getElementById('agreementDiv' + jdkTag).getAttribute('style') === 'visibility: hidden;');
    }, {
        jdkTag: jdkTag    
    });
  }, function then() {
//    this.capture('acceptedLicense.png', {top:0, left:0, width:1200, height:800});
    downlink = this.evaluate(function(jdkFileLink) {
      var jdkElement = document.getElementById(jdkFileLink);
      if (jdkElement) {
        var jdkLink = jdkElement.getAttribute("href");
        jdkElement.click();
        return jdkLink;
      }
    }, {
      jdkFileLink: jdkFileLink
    });
  }, null, 5000);
});

casper.run();

download.sh

#!/bin/bash

url=$(casperjs --web-security=no oraclejdk.js |grep "http://download.oracle.com/otn/java/jdk" $() | sed -e 's/^.*: //')
jdk=$(echo "${url}" | sed -e 's/^.*jdk-/jdk/' |sed -e 's/?.*//')
wget -O "${jdk}" "${url}"
h.ozawa
  • 71
  • 1
  • 2
0

This is not a direct answer to your question...but Here is how i get URL to latest jdk download URL

#!/bin/bash

jdkwebinstallerDownloadPage="https://www.oracle.com"$(curl -s https://www.oracle.com/technetwork/java/javase/downloads/index.html | unix2dos | grep "<a name=\"JDK8\"" | sed 's/^.*\<a name=\"JDK8\" href=//g' | sed -r 's/>.*//g' | sed s/\"//g)
## Above yields https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 

jdkinstallerDownloadURL=$(curl -s $jdkwebinstallerDownloadPage | grep windows | grep downloads | grep x64 | grep jdk | grep -v demos | sed -r 's/^.*https/https/g' | sed -r 's/\".*//g') 
## yields https://download.oracle.com/otn/java/jdk/8u221-b11/230deb18db3e4014bb8e3e8324f81b43/jdk-8u221-windows-x64.exe  

I am now looking to how to download from this url using wget...given that i have cedentials to login into oracle's login webpage which is https://login.oracle.com/mysso/signon.jsp

hardeep
  • 186
  • 1
  • 7