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}"