1

Is there any API to get the latest JAVA 8. For my automatic build system I need to get the latest version.

something like: wget https://oracle.com/api/download/jre/8/Linux x64/lastest which would give me the latest version (build version in this case u131, as of 05.05.17)

Or would i need to go to http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html , do the acceptLicense-JS, parse the html and get the link myself?

  • It's pretty unreasonable to download the whole JRE every time you do a build? – Seth May 5 '17 at 8:23
  • I build a standalone version of my package. This requires an jre. C urrently I am stuck on the build version, i copy to my working directory. – Joel May 5 '17 at 8:26
  • So update it every once in a while or at least check whenever there is a newer version available before you download it? Pulling it for every build not only would mean a certain bloat but also a considerable wait time. While not incredibly reliable checking the checksum link on the download page would be an option. Also check this for the DL using wget you probably would have to grab the link manually. There is a downloads JS array on that page that contains the links. – Seth May 5 '17 at 9:20
  • sure, i would first check, if there is a new build version, iff so, dowload and cache loacally. Then build my package. However, where is this JS array? I looked at your link, but was not able to find the array of links – Joel May 5 '17 at 9:25
  • 1
    The other question has instructions how to simply use wget to do the download. You will still need to get the current download link. But you won't have to execute the actual JS to get those links. The original download page you linked contains a downloads JS array that you might be able to identify and grab. E.g. you could look for ['files']['jre-8u131-windows-x64.tar.gz'] to find the right line after you identified the current version using the checksum link. – Seth May 5 '17 at 9:39
1

For my automatic build system I need to get the latest version.

You can use either weget or curl to do this.


Solution 1 Using wget

Use wget and use a special cookie to bypass the licence agreement:

a single cookie is all that is needed to bypass this (you still have to agree to the terms to install)

The cookie is:

Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie

Example

if you want to download jdk7u4 for 64-bit Linux (e.g., Ubuntu) using wget, you can use:

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u4-b20/jdk-7u4-linux-x64.tar.gz"

Source Download Oracle Java JRE & JDK using a script


Solution 1 Using curl

There is a shell script that completely automates the download.

downloadJavaAutomatic.ksh

#!/bin/ksh

###################################
## Overview
###################################

# Downloads JDK & JRE from download.oracle.com by first walking possible combinations of available version/build numbers.
# Once a version/build is found, subsequent attempts in the same family are primed to avoid walking the entire tree again.
# 
# version=<x> represents the highest attempted version number while walking the tree
# build=<y> represents the highest attempted build number while walking the tree
#
# Adjust "BASE" to control which versions are downloaded.  A value of 8 corresponds to Java-v1.8.x
# Likewise a value of "6 7 8" equates to Java-v1.6.x, Java-v1.7.x, Java-v1.8.x
#
# Adjust "PLATFORMS" to match the architecture platforms you wish to download.
#
# Reference URLS:
# https://gist.github.com/P7h/9741922
# http://download.oracle.com/otn-pub/java/jdk/8u40-b26/jre-8u40-windows-x64.exe
# http://download.oracle.com/otn-pub/java/jdk/8u40-b27/jdk-8u40-macosx-x64.dmg

###################################
## Usage
###################################

# downloadJavaAutomatic.ksh
# Finds and downloads current Java versions

# downloadJavaAutomatic.ksh [-f <file>]
# Skips version/build find routing, uses external <file>
# which contains a list of URLs to be downloaded.


###################################
## Config
###################################
version=99
build=30

set -A BASE 8 7 6 
set -A BASE 7 
set -A PLATFORMS -- -linux-x64.tar.gz -linux-i586.tar.gz -macosx-x64.dmg -windows-i586.exe -windows-x64.exe 

###################################
## Subroutines
###################################

doCountCurl() {
    ps -ef | egrep -ie "curl.*${cookie}" | grep -vi grep | wc -l
}

doGetURL() {
    printf "\n$URL\n" 
    Cookie="Cookie:oraclelicense=accept-securebackup-cookie"
    curl -O -L -S -H "${Cookie}" --progress-bar --connect-timeout 55 --fail -k "${1}" 
    if [[ $? -ne 0 ]]; then
        echo ERROR - download failed.
    fi
}

doTestURL() {
    uri_local=$1
    base_local=$2
    version_local=$3
    build_local=$4
    platform_local=$5
    type_local=$6

    Cookie="Cookie:oraclelicense=accept-securebackup-cookie"
    URL="http://download.oracle.com/${uri_local}${base_local}u${version_local}-b${build_local}/${type_local}-${base_local}u${version_local}${platform_local}"
    curl --output /dev/null -L -sS -H "${Cookie}" --head --connect-timeout 15 --max-time 30 --fail -k "${URL}" 2>/dev/null
    if [[ $? -eq 0 ]]; then
        echo $URL >> $urlFile
        printf  "$version_local" > $tmpVersion
        printf  "$build_local" > $tmpBuild
        printf  "${URL}" > $tmpFile
        break
    fi
}

doFindVersionBuild() {
    URI=$1
    BASE=$2
    PLATFORM=$3
    TYPE=$4

    ### If available use version to limit tree walking
    if [[ -e $tmpVersion ]]; then
        version_cnt=$(( `cat $tmpVersion` ))
    else
        version_cnt=$version 
    fi

    while [[ $version_cnt -ge 1 ]] && [[ ! -e $tmpFile ]]; do

        ### If available use build to limit tree walking
    if [[ -e $tmpBuild ]]; then
            build_cnt=$(( 10 + `cat $tmpBuild` ))
        else
            build_cnt=$build 
        fi

        ### Keep going until a version is found
    while [[ $build_cnt -ge 1 ]] && [[ ! -e $tmpFile ]]; do
            ### Limit HTTP connections to avoid saturating connection
        maxHTTP=50; while [[ `doCountCurl` -ge ${maxHTTP} ]]; do sleep 1; done

            ### Send to background to speed up process
            doTestURL ${URI} ${BASE} ${version_cnt} ${build_cnt} ${PLATFORM} ${TYPE} &
            (( build_cnt-=1 ))
        done

        (( version_cnt -= 1 ));
        sleep 1
    done 

    ### Wait for current version/build series to finish before starting next round
    while [[ `doCountCurl` -gt 0 ]]; do sleep 1; done

    ### Save results to VERSION array.  Highest version will be element #1
    set -A VERSION dummy `[[ -e $tmpFile ]] && sort -nr $tmpFile`
    if [[ "${VERSION[1]}" != "" ]]; then
        echo ${VERSION[1]}
    else
        printf -- "${TYPE}-${BASE}u??${PLATFORM} - No Version found.\n"
    fi

    ### Cleanup
    if [[ -e $tmpFile ]]; then
        rm $tmpFile
    else
        [[ -e $tmpVersion ]] && rm $tmpVersion
        [[ -e $tmpBuild ]] && rm $tmpBuild
    fi
}

doDownload() {
    printf "\nDownloading...\n"
    for URL in $( grep -vi "#" $urlFile ); do
        doGetURL "$URL"
    done
}

#########################
### Main 
#########################
tmpFile=$$-tmp.txt
tmpVersion=$$-version.txt
tmpBuild=$$-build.txt
urlFile=url.txt

clear
if [[ $1 = "-f" ]] && [[ -r "$2" ]]; then
    echo "Search for version/build bypassed.  Using URLs within file: $2"
    urlFile=$2
    doDownload
else
    printf "Searching for available versions...\n\n"

    for base in ${BASE[@]}; do
        for type in $(echo jre jdk); do
            printf "# `date`\n" >> $urlFile
            for platform in ${PLATFORMS[@]}; do
                URI=otn-pub/java/jdk/
                doFindVersionBuild ${URI} ${base} ${platform} ${type}
            done
        done
        ### Delete version and build markers before attempting next BASE version. 
        [[ -e $tmpVersion ]] && rm $tmpVersion
        [[ -e $tmpBuild ]] && rm $tmpBuild
    done
    doDownload
fi

[[ -e $urlFile ]] && rm $urlFile

Source Java-JRE-JDK-Downloader

  • Doesnt work for me as it turns out, that the urls like http://download.oracle.com/otn-pub/java/jdk/8u87-b1/jre-8u87-linux-x64.rpm dont give the package, as required by the script. The script might need to be updated. – Joel May 12 '17 at 5:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.