Code Monkey home page Code Monkey logo

install-jdk's Introduction

install-jdk

Python Version MI Release CodeQL Codacy Badge Commit History PyPI Downloads Badge PyPI Version Badge

The install-jdk library is a Python package that simplifies the process of installing OpenJDK on Windows, macOS, Linux and other supported operating systems, saving time and effort. install-jdk is a useful tool for users, developers, and system administrators who need to set up Java development environment or runtime in an automated and repeatedable fashion.

install-jdk has no third-party dependencies and depends solely on the standard libraries found in Python3. This means that you can easily install and use the library without having to install any additional dependencies.

install-jdk aims to provide as many options as possible to install an OpenJDK Java version across a wide array of operating systems and architectures. Please see each vendors OpenJDK documentation to see what operating systems and architectures they support.

Supported OpenJDK Build Vendors

OpenJDK Build Status Vendor Tags Vendor Documentation install-jdk Documentation Source Code
Adoptium (default) Implemented Adoptium, Temurin, AdoptOpenJDK, eclipse Adoptium Adoptium Build Client docs Adoptium Build Client src
Corretto Implemented Corretto, Amazon, AWS Corretto Corretto Build Client docs Corretto Build Client src
Microsoft Planning Microsoft ...coming soon
Azul Implemented Azul, Zulu Azul Zulu ...coming soon Zulu Build Client src

install-jdk will do its best to detect the operating system and architecture that it is running on. Currently is able to detect:

  • Operating Systems

    • Windows
    • Linux
    • MacOS
    • AIX
  • Architecture

    • arm
    • aarch64
    • ppc64
    • x64
    • x86

Installation

To install the install-jdk library, simply run the following command:

pip install install-jdk

Usage

To use the install-jdk library, import it into your Python code:

import jdk

The library provides an install function, which takes the following parameters:

  • version - The major version of the Java OpenJDK build to install (e.g. 8, 11, 17, etc.).
  • operating_system - The target operating system. If not specified, will use the user's detected operating system if possible.
  • arch - The target architecure. If not specified, will use the user's detected architecture if possible.
  • impl - The Java implementation to use. Currently only supports HOTSPOT and dependent on the OpenJDK Build Vendor.
  • jre - A boolean value indicating that the Java Runtime Environment should be installed. Defaults to false, which will install the Java Development Kit.
  • path - The location to install the downloaded OpenJDK build. If not specified, will install into $HOME/.jdk/<VERSION> for the Java Development Kit and $HOME/.jre/<VERSION> for the Java Runtime Environment.
  • vendor - The vendor to download the OpenJDK build from. If not specified, defaults to Adoptium. This is a named argument so must be provided like vendor='Corretto'. Please see the list of Supported OpenJDK Build Vendors

Here are some example code snippet:

jdk.install('11')
# Platform dependent install of Java JDK 11 into $HOME/.jdk/<VERSION>

jdk.install('11', jre=True)
# Platform dependent install of Java JRE 11 into $HOME/.jre/<VERSION>

jdk.install('17', vendor='Corretto')
# Installs a Corretto build of Java 17 JDK. Defualt vendor is Adoptium

jdk.install('17', vendor='Corretto', path='/usr/local/jdk')
# Installs a Corretto build of Java 17 JDK into /usr/local/jdk

The library also has a get_download_url function that returns the URL for the given version, it takes the following parameters:

  • version - The major version of the Java OpenJDK build to install (e.g. 8, 11, 17, etc.).
  • operating_system - The target operating system. If not specified, will use the user's detected operating system if possible.
  • arch - The target architecure. If not specified, will use the user's detected architecture if possible.
  • impl - The Java implementation to use. Currently only supports HOTSPOT and dependent on the OpenJDK Build Vendor.
  • jre - A boolean value indicating that the Java Runtime Environment should be installed. Defaults to false, which will install the Java Development Kit.
  • vendor - The vendor to download the OpenJDK build from. If not specified, defaults to Adoptium. This is a named argument so must be provided like vendor='Corretto'. Please see the list of Supported OpenJDK Build Vendors

Here are some example code snippets:

from jdk.enums import OperatingSystem, Architecture

download_url = jdk.get_download_url('17', jre=True)
print(download_url)
# Obtains the platform dependent JRE download url

download_url = jdk.get_download_url('17', operating_system=OperatingSystem.LINUX, arch=Architecure.AARCH64, vendor='Corretto')
print(download_url)
# Obtains OpenJDK 17 from Corretto for Linux running on aarch64

The library has a download function that will download the requested version and returns back the path to where it was downloaded. This function does not currently support overriding the default download path which is the operating systems specific TMP directory. It takes the following parameters.

  • download_url - The URL to the file to be downloaded. Defaults to None.
      • version - Required when download_version is None and must be provided as a named parameter. The major version of the Java OpenJDK build to install (e.g. 8, 11, 17, etc.).
  • operating_system - Must be provided as a named parameter. The target operating system. If not specified, will use the user's detected operating system if possible.
  • arch - Must be provided as a named parameter. The target architecure. If not specified, will use the user's detected architecture if possible.
  • impl - Must be provided as a named parameter. The Java implementation to use. Currently only supports HOTSPOT and dependent on the OpenJDK Build Vendor.
  • jre - Must be provided as a named parameter. A boolean value indicating that the Java Runtime Environment should be installed. Defaults to false, which will install the Java Development Kit.
  • vendor - The vendor to download the OpenJDK build from. If not specified, defaults to Adoptium. This is a named argument so must be provided like vendor='Corretto'. Please see the list of Supported OpenJDK Build Vendors

Here are some example code snippets:

from jdk.enums import OperatingSystem, Architecture

download_file = jdk.download('https://api.adoptium.net/v3/binary/latest/17/ga/windows/x64/jdk/hotspot/normal/eclipse')
print(download_file)
# Downloads the requested file and returns back the TMP locations it was stored in.

download_file = jdk.download(version='17', operating_system=OperatingSystem.LINUX, arch=Architecure.AARCH64, vendor='Corretto')
print(download_file)
# Downloads the a Linux aarch64 build of Java 17 from Corretto and returns back the TMP location it was stored in.

The library also provided two helper properties that can be used to see what it detected as the user's operating system and architecture.

print(jdk.OS)
print(jdk.ARCH)

Credits

The install-jdk library uses OpenJDK builds, and is created and maintained by jyksnw.

This was originally a port of the GitHub Action installjdk but has morphed into something much more.

Vendor Credits

License

The install-jdk library is open-source and is distributed under the MIT license. See the LICENSE file for more information.

Contribution

See CONTRIBUTING

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Sponsor This Project

GitHub Sponser

Tidelift

Buy Me A Coffee

install-jdk's People

Contributors

dependabot[bot] avatar jyksnw avatar robbie-palmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

install-jdk's Issues

macOS Install Fails because of 404 error

When using on macOS the platform is reported back as darwin which then sets the url to pull for the OS darwin which is not a valid OS on the API. When darwin is detected the OS should be set to mac to comply with the API.

TypeError: str.join()

I run --

jdk.install('17')  # with and without a path argument

It looks like JDK downloads, but is perhaps failing at the extract step. I'm using Linux (x86_64, Ubuntu 22.04-based distro). Here's the output --

Traceback (most recent call last):
  File "_____/env/lib/python3.10/site-packages/jdk/__init__.py", line 102, in install
    jdk_dir = _decompress_archive(jdk_file, jdk_ext, path)
  File "_____/env/lib/python3.10/site-packages/jdk/__init__.py", line 70, in _decompress_archive
    jdk_directory = extractor.extract_files(
  File "_____/env/lib/python3.10/site-packages/jdk/extractor.py", line 71, in extract_files
    _safe_extract(tar, path=destination_folder)
  File "_____/env/lib/python3.10/site-packages/jdk/extractor.py", line 45, in _safe_extract
    member_path = path.join(path, member.name)
TypeError: str.join() takes exactly one argument (2 given)

Let me know if you need more info.

test.pypi.org project name

@Robbie-Palmer, I am revamping this library and see that you have claimed the install-jdk project on test.pypi.org. Can you release that project name by deleting your copy so I can get a proper release pipeline setup?

Cannot access Adoptium on Mac M2

Hello, I am trying to install jdk on my new mac and recieve a 404 error when trying to run jdk.install('17')).

I can run jdk.install('17', vendor='Azul')) as well as access that link directly in web browser.

However, for Adoptium, when running jdk.get_download_url('17') I get the following link for mac arm, which cannot be accessed from a web browser:
https://api.adoptium.net/v3/binary/latest/17/ga/mac/arm/jdk/hotspot/normal/eclipse

However, I changed to this architecture and this url works:
https://api.adoptium.net/v3/binary/latest/17/ga/mac/aarch64/jdk/hotspot/normal/eclipse

Any help for quickest way to setup on Mac M2 would be great and thanks in advance

Rerunning jdk.install on already installed version throws an error

When running jdk.install on a version that is already installed, the following error is raised:

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Jason\Documents\GitHub\install-jdk\jdk_init_.py", line 93, in install
raise e
File "C:\Users\Jason\Documents\GitHub\install-jdk\jdk_init_.py", line 90, in install
jdk_dir = decompress_archive(jdk_file, jdk_ext, path)
File "C:\Users\Jason\Documents\GitHub\install-jdk\jdk_init
.py", line 60, in _decompress_archive
jdk_directory = extractor.extract_files(jdk_file, file_ending, destination_folder)
File "C:\Users\Jason\Documents\GitHub\install-jdk\jdk\extractor.py", line 72, in extract_files
jdk_directory = next(iter(end_listing.difference(start_listing)))
StopIteration

cgi is deprecated and slated for removal in Python 3.13

..\..\..\AppData\Python311\Lib\site-packages\jdk\client\client.py:1
  D:\AppData\Python311\Lib\site-packages\jdk\client\client.py:1: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
    import cgi

Pass to adoptium

It seems that the current URL api.adoptopenjdk.net is deprecated (see home page), and that the URL should be changed to api.adoptium.net.

There is a migration guide that could be follow.

Setup Nox and PyTest

The project needs to be able to test better that there are no breaking changes in its supported Python version (targets 3.6+), along with its support for OpenJDK clients, platforms, and architectures. To support this, the project should be updated to use PyTest with some unit tests defined along with Nox to run those unit tests against various Python versions.

Reconciling with cjdk and/or jvm-index

Hello! 👋 I'm an author of jgo, and my colleague @marktsuchida is the author of cjdk. The cjdk project fills a very similar need to install-jdk, providing a command-line tool written in Python for downloading and caching JDKs. It uses jvm-index from the Coursier project as its source of truth for which JVM implementations are available from where, which makes things a bit easier.

For a while now, we have been scheming—when we have some spare time, which of course no one ever has...—to make cjdk a dependency of jgo, such that jgo can not only launch Java code from remote Maven repositories from the CLI, but also do so without a JDK/JRE already being present and available. However, since cjdk was written, we noticed that install-jdk has been actively developed for the past few months.

Therefore, I'm reaching out to get your thoughts on how—if at all—all of these projects might work together for the betterment of the community.

  • Were you already aware of cjdk? If so, how do you see the respective niches of install-jdk vs cjdk? Or if not, do you think it would make sense to join forces and share/consolidate any code?
  • Did you already know about the jvm-index? Maybe using it could help install-jdk to save some code in its implementation?
  • If cjdk and install-jdk could be combined into a single project meeting all requirements, that would be awesome. But if not, what do you think might be the best way forward for jgo to integrate some JDK-downloading functionality? Should I just pick one of cjdk or install-jdk, or might there be reasons to bake in both as options?

Looking forward to reading your thoughts! 😄

Does install-jdk support Python 3.8?

I'm told that import jdk raises a "TypeError: 'type' object is not subscriptable" exception in Python 3.8, and that this is a Python 3.8 issue. Did you drop support for Python 3.8? Your pyproject.toml file mentions Python 3.8 and the pypi page says 3.8 in the requirements section but lists 3.9 in the classifiers. Also, your readme has a Python 3.9-3.11 badge. If you don't support Python 3.8 anymore, that's fine, I can update my documentation to make that clear, but it would be helpful if pypi's requirements were for >= 3.9 so users couldn't install it on 3.8.

Thanks!

Guidance to add `aarch64` support

Dear @jyksnw,

Context: @claudefalbriard and I would like to add support to Rasberry Pi, because we'd like to use it for educational activities involving py5 (@py5coding). We use @tabreturn's Thonny IDE plugin (https://github.com/tabreturn/thonny-py5mode) that helps set up JDK for py5 and depends on install-jdk.

I have experimented with os.uname().machine and it looks promissing to identify architecture.

Also, visiting https://api.adoptopenjdk.net/ I saw a warning about moving to https://api.adoptium.net and this guide: https://api.adoptopenjdk.net/migration.html

Would you like to guide us to a PR (or maybe more than one) that could address these issues?

Add "OpenJDK" to PyPi description for SEO

Minor (but annoying!) issue!

Steps to reproduce:

  1. Search PyPi.org for "openjdk."

Expected Behavior

install-jdk somewhere near the top of results.

Actual Behavior

install-jdk not in results at all.

Happily it does show at the top when searching for "JDK" but a little SEO never hurt anyone.

[Errno 13] Permission denied: ASSEMBLY_EXCEPTION'

When I run

jdk.install('11', jre=True)

It return the following error and I don't know what to do:
[Errno 13] Permission denied: '/home/user/.jre/jdk-11.0.11+9-jre/legal/java.transaction.xa/ASSEMBLY_EXCEPTION'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.