» pip install install-jdk
Videos
I dont know if it ispossible (install JAVA through PIP) my guess is it is not. But what you have done with "pip install install-jdk" is just intalled a Python library called install-jdk. To have this working you need a python script that import this library and call the function who install JAVA. See https://pypi.org/project/install-jdk/
it sounds like you haven't downloaded the official java yet.
you have to download java via their official website first https://www.oracle.com/java/technologies/downloads/
afterwards, remember to set your PATH (under environment variables) to route to the correct java path
» pip install jdk4py
Extracting MSI files from the Java install prompted me to work up a method to keep Java updates in our WPKG share current. So here it is. Probably not the best Python, but it's functional (Python 2, should be adaptable to Python 3 easily). If you use a different deployment method (other than WPKG), you'll obviously need to adjust update_java_packages accordingly.
Features
Checks for latest Java 8 version from Javascript embedded in https://java.com/en/download/installed8.jsp
Stores JRE and JDK license acceptance in cookie before downloading. Of course you've agreed to it in the past.
Downloads latest JRE and JDK, runs installers long enough to copy extracted MSI and CAB files to destination folder.
Updates WPKG package files with new update numbers.
Records latest update downloaded, so the script can exit quickly if there's no new updates.
Scripts and support files stored in a single folder:
Win32 build of wget.exe
Most likely downloaded from https://eternallybored.org/misc/wget/.
update-java.py
#!/usr/bin/env python
from string import Template
from datetime import datetime, timedelta
import subprocess
import os
import glob
import shutil
import time
def unix_time(dt):
epoch = datetime.utcfromtimestamp(0)
return int((dt - epoch).total_seconds())
def make_cookies(cookies):
cookieTemplate = Template('.${domain}\t${allmachines}\t${path}\t${secure}\t${expiration}\t${name}\t${value}\n')
tomorrow = unix_time(datetime.now() + timedelta(days=1))
d = dict(
domain = 'oracle.com',
allmachines = 'TRUE',
path = '/',
secure = 'FALSE',
expiration = tomorrow,
name = 'oraclelicense',
value = 'accept-securebackup-cookie'
)
cookieString = cookieTemplate.safe_substitute(d)
with open(cookies,'w') as f:
f.write(cookieString)
def find_latest_update(version):
versionUrl = Template("http://java.com/en/download/installed${version}.jsp")
url = versionUrl.safe_substitute(version=version)
output = subprocess.check_output(["wget", "-qO-", url])
tagLine = Template("latest${version}Version").safe_substitute(version=version)
for line in output.split('\n'):
if tagLine in line:
#print line
(_, versionString, _) = line.split("'")
# print versionString # 1.8.0_101
(_, update) = versionString.split("_")
# print update # 101
return int(update)
def download_java(kinds, version, update, cookies):
site = "http://download.oracle.com/otn-pub/java/jdk"
b = 13 # not sure how often this changes
archList = ["windows-x64", "windows-i586"]
urlTemplate = Template("${site}/${version}u${update}-b${b}/${package}-${version}u${update}-${arch}.exe")
for arch in archList:
for package in kinds:
d = dict(
site = site,
package = package,
version = version,
update = update,
b = b,
arch = arch
)
url = urlTemplate.safe_substitute(d)
print "Downloading %s" % (url)
cookieFlag = "--load-cookies=%s" % (cookies)
subprocess.call(["wget", "-q", cookieFlag, url],
cwd = os.getcwd())
def copy_java_contents(kinds, version, update, msiDestination):
# For each executable with correct version and update
patternTemplate=Template("${kind}-${version}u${update}-windows-*.exe")
for kind in kinds:
d = dict(
kind = kind,
version = version,
update = update
)
pattern = patternTemplate.safe_substitute(d)
olddir = os.getcwd()
for file in glob.glob(pattern):
print file
# - Make a directory in wpkg/software
(_, _, _, archexe) = file.split("-")
if archexe=="i586.exe":
arch = "x86"
elif archexe=="x64.exe":
arch = "x64"
path = msiDestination + (r'\%s\%d\%d-%s '[:-1] % (kind,
version,
update,
arch))
print "Will makedirs(%s) if needed" % (path)
if not os.path.isdir(path):
os.makedirs(path, mode = 0755)
# - Run the executable to extract contents to temp
print "Starting %s" % (file)
proc = subprocess.Popen([file], shell=False)
print "Started %s as %s" % (file, proc)
# - Copy contents to wpkg directory
extract_parent = os.path.join(os.environ['USERPROFILE'], 'Appdata',
'LocalLow', 'Oracle', 'Java')
print "Chccking for extract parent directory %s..." % (extract_parent),
while not os.path.isdir(extract_parent):
time.sleep(1)
os.chdir(extract_parent)
print "done."
if arch=="x64":
tempFolder = "%s1.%d.0_%d_%s" % (kind, version, update, arch)
else:
tempFolder = "%s1.%d.0_%d" % (kind, version, update)
print "Checking for extract directory...",
while not os.path.isdir(tempFolder):
time.sleep(1)
os.chdir(tempFolder)
print "done."
print "Sleeping for 10 seconds...",
time.sleep(10)
print "done."
# - Kill the executable
subprocess.call(['taskkill', '/F', '/T', '/PID', str(proc.pid)])
print "Copying files...",
for f in glob.glob("*.msi"):
shutil.copy(f,path)
for f in glob.glob("*.cab"):
shutil.copy(f,path)
print "done."
os.chdir('..')
# - Remove contents from temp
shutil.rmtree(tempFolder)
os.chdir(olddir)
def update_java_packages(kinds, version, update, wpkgRoot, branches):
for kind in kinds:
for branch in branches:
sourceXML = "%s-%d.xml" % (kind, version)
with open(sourceXML) as templateXML:
lines=templateXML.readlines()
template = Template( ''.join(lines) )
d=dict(update=update)
targetXML = os.path.join(wpkgRoot,branch,'packages',sourceXML)
with open(targetXML,'w') as packageXML:
packageXML.writelines(template.safe_substitute(d))
def check_local_update(msiDestination, version):
localfile = os.path.join(msiDestination, 'jdk', str(version),
'localVersion.txt')
try:
with open(localfile, 'r') as f:
lines = f.readlines()
update = int(lines[0])
except IOError:
update = 0
return int(update)
def write_local_update(msiDestination, version, update):
localVersionFile = os.path.join(msiDestination, 'jdk', str(version),
'localVersion.txt')
with open(localVersionFile, 'w') as f:
f.write(str(update))
if __name__ == "__main__":
version = 8
cookies = 'cookies.txt'
kinds = ["jdk", "jre"]
#wpkgRoot = r'\\some.server.fqdn\wpkg '[:-1]
wpkgRoot = r'c:\users\someuser\desktop\wpkg-tmp '[:-1]
msiDestination = wpkgRoot+r'\software '[:-1]
branches = [ 'dev', 'stable' ]
print "Checking for latest update to Java %d" % (version)
update = find_latest_update(version = version)
print "It's update %s" % (update)
localUpdate = check_local_update(msiDestination = msiDestination,
version = version)
if localUpdate < update:
print "Local copy (%d) is out of date." % (localUpdate)
print "Making cookies"
make_cookies(cookies)
download_java(kinds = kinds,
version = version,
update = update,
cookies = cookies)
copy_java_contents(kinds = kinds,
version = version,
update = update,
msiDestination = msiDestination)
update_java_packages(kinds = kinds,
version = version,
update = update,
wpkgRoot = wpkgRoot,
branches = branches)
write_local_update(msiDestination = msiDestination,
version = version, update = update)
else:
print "Local copy (%d) is current." % (localUpdate)jdk-8.xml
<!--
Automatically generated from update-java.py and software\jdk\jdk-8.xml template file.
Do not edit packages\jdk-8.xml manually.
-->
<!-- From http://wpkg.org/Java -->
<!-- See jre-6.xml for instructions -->
<packages>
<package id='jdk-8' name='Java Development Kit 8' priority='548' reboot='postponed' revision='%update%'>
<variable name='version' value='8' />
<variable name='update' value='${update}' />
<variable name='uninstall_name' value='Java SE Development Kit %version% Update %update% (64-bit)' architecture='x64' />
<variable name='uninstall_name' value='Java SE Development Kit %version% Update %update%' architecture='x86' />
<check condition='exists' path='%uninstall_name%' type='uninstall' />
<variable architecture="x64" name="source" value="%SOFTWARE%\jdk\8\%update%-x64" />
<variable architecture="x86" name="source" value="%SOFTWARE%\jdk\8\%update%-x86" />
<install cmd='taskkill /f /im jqs.exe /im iexplore.exe /im firefox.exe'>
<exit code='0' />
<exit code='1' />
<exit code='128' />
</install>
<install cmd='msiexec /qn /i "%source%\jdk1.%version%.0_%update%.msi" JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 RebootYesNo=No WEB_JAVA=1 INSTALLDIR="%PROGRAMFILES%\Java\JDK\"' />
<upgrade include='install' />
<remove cmd='msiexec /qn /x{64A3A4F4-B792-11D6-A78A-00B0D01%version%0%update%0}'>
<exit code='1605' />
</remove>
</package>
</packages>jre-8.xml
<!--
Automatically generated from update-java.py and software\jdk\jre-8.xml template file.
Do not edit packages\jre-8.xml manually.
-->
<!-- From http://wpkg.org/Java -->
<!-- See jre-6.xml for instructions -->
<packages>
<package id='jre-8' name='Java Runtime Environment 8' priority='879' reboot='postponed' revision='%update%'>
<variable name='version' value='8' />
<variable name='update' value='${update}' />
<variable name='uninstall_name' value='Java %version% Update %update%'/>
<check condition='exists' path='%uninstall_name%' type='uninstall' />
<variable name="source" value="%SOFTWARE%\jre\8\%update%-x86" />
<variable architecture="x64" name="dest" value="%PROGRAMFILES(x86)%\Java\JDK" />
<variable architecture="x86" name="dest" value="%PROGRAMFILES%\Java\JDK" />
<install cmd='taskkill /f /im jqs.exe /im iexplore.exe /im firefox.exe'>
<exit code='0' />
<exit code='1' />
<exit code='128' />
</install>
<install cmd='msiexec /qn /i "%source%\jre1.%version%.0_%update%.msi" JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 RebootYesNo=No WEB_JAVA=1 INSTALLDIR="%DEST%"' />
<upgrade include='install' />
<remove cmd='msiexec /qn /x{26A24AE4-039D-4CA4-87B4-2F8321%version%0%update%F0}'>
<exit code='1605' />
</remove>
</package>
<package id='jre-8-x64' name='Java Runtime Environment 8 (64-bit)' priority='878' reboot='postponed' revision='%update%'>
<variable name='version' value='8' />
<variable name='update' value='${update}' />
<variable name='uninstall_name' value='Java %version% Update %update% (64-bit)' architecture='x64' />
<check condition='exists' path='%uninstall_name%' type='uninstall' />
<variable architecture="x64" name="source" value="%SOFTWARE%\jre\8\%update%-x64" />
<variable architecture="x64" name="dest" value="%PROGRAMFILES%\Java\JDK" />
<install cmd='taskkill /f /im jqs.exe /im iexplore.exe /im firefox.exe'>
<exit code='0' />
<exit code='1' />
<exit code='128' />
</install>
<install cmd='msiexec /qn /i "%source%\jre1.%version%.0_%update%.msi" JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 RebootYesNo=No WEB_JAVA=1 INSTALLDIR="%DEST%"' />
<upgrade include='install' />
<remove cmd='msiexec /qn /X{26A24AE4-039D-4CA4-87B4-2F8641%version%0%update%F0}'>
<exit code='1605' />
</remove>
</package>
</packages>Usage:
From a command prompt in the folder containing the support files:
C:\path\to\folder>update-java.py Checking for latest update to Java 8 It's update 101 Local copy (0) is out of date. Making cookies Downloading http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-windows-x64.exe ... Chccking for extract parent directory C:\Users\someuser\Appdata\LocalLow\Oracle\Java... done. Checking for extract directory... done. Sleeping for 10 seconds... done. SUCCESS: The process with PID 4144 (child process of PID 2664) has been terminated. SUCCESS: The process with PID 2664 (child process of PID 2240) has been terminated. Copying files... done. C:\path\to\folder>update-java.py Checking for latest update to Java 8 It's update 101
I am only coding in Python. Do I need JDK or any java related installation if I am using Python?