How do I bypass the license page to download Oracle/Sun Java on a server with wget?

Solution 1:

"Automated" Oracle Java Downloads (JRE/JDK 6/7 and others...)

You will need sqlite3 installed; it's a tiny package, use sudo apt-get install sqlite3 if you need to.

  1. Open Firefox, go to the Java downloads page for the version/variant you need, and click on the Accept License Agreement radio button.

    • For example, here's the Java 6 SE download page:

    enter image description here

  2. Open a terminal, and paste this to extract the necessary Oracle session cookies from the Firefox SQLite cookie database into a cookies format text file wget can use (source for script):

    echo ".mode tabs
    select host, case when host glob '.*' then 'TRUE' else 'FALSE' end, path,
    case when isSecure then 'TRUE' else 'FALSE' end, expiry, name, value
    from moz_cookies;" | sqlite3 ~/.mozilla/firefox/*.default/cookies.sqlite
    | grep -i oracle > /tmp/oracle-cookies.txt
    
  3. Now use wget to download with those session cookies:

    wget --load-cookies=/tmp/oracle-cookies.txt wget http://download.oracle.com/otn-pub/java/jdk/6u14-b08/jdk-6u14-linux-x64.bin
    
  4. Notes:

    • You can use these cookies for any Oracle download as long as it comes from the otn-pub directory
    • You can paste the script in to a .sh file for easier use
    • The cookies are not associated with IP, so for a headless/CLI server, simply SCP or transfer the cookies file and you can download from any computer (but there is a 30-minute timeout on the cookie, so beware)
    • Related: How do I use wget/curl to download from a site I am logged into?

Solution 2:

There is a similar question on stackoverflow: How to automate download and instalation of Java JDK on Linux?

The answer using wget is:

wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com" "http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz"

The last argument is the url to download from. Different java version archives differ not only in version, but extension too.

Solution 3:

A tip from mkyong.com: you can use wget --header "Cookie: oraclelicense=accept-securebackup-cookie" [link from download page] to download without needing to extract cookies from your browser.

Solution 4:

As an addition to izx answer, there is a chrome plugin you can use to export your cookies, so you do not have to use sqlite.