GithubHelp home page GithubHelp logo

djcking / jdkman Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wkgcass/jdkman

0.0 0.0 0.0 201 KB

Manage multiple JDK instances.

License: GNU General Public License v2.0

Java 96.80% Rust 3.20%

jdkman's Introduction

jdkman

What is jdkman

jdkman is a command line tool which helps you manage multiple JDK instances.

An asciinema cast shows how to use jdkman.
This video shows how to configure jdkman on Windows.

How to install

1. Download

Download the pre-built binary from the release page.
You will need to download the binary corresponding to your operating system and cpu architecture.

Rename the downloaded file jdkman-$os-$arch to jdkman
You will also need to run chmod +x jdkman on Linux or macOS.

2. Configure

bash or zsh

Add the following lines in your ~/.bashrc or ~/.bash_profile or ~/.zshrc

## add jdkman to your PATH environment variable.
export PATH="$PATH:/path/to/jdkman"
eval "`jdkman init sh`"

Powershell

Add \path\to\jdkman to your PATH environment variable.

Then configure the profile script by entering the following lines in powershell:

echo $profile ## show the profile script location
New-Item -ItemType Directory -Path (Split-Path $profile) -Force
'Invoke-Expression -Command (jdkman init pwsh)' | Out-File -FilePath $profile -Append

Windows cmd

Since cmd doesn't support eval nor source, there's very little that jdkman could provide.

Add \path\to\jdkman to your PATH environment variable.
Add \YourHomePath\jdkman-scripts to your PATH environment variable.

Then in cmd, run once (for each time you upgrades jdkman):

jdkman init

You can ignore the init output.

How to use

1. Add JDKs

jdkman add /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home

2. Show JDKs

jdkman list

3. Set JDK version for each project

Add a file .java-version in the root directory of your project with the following content:

21

21 could be changed to any JDK versions, e.g. 11, 11.0.2, 1.8.
jdkman will find the most appropriate JDK version for you.

You could also specify the implementor (or vendor) of the JDK:
Specify the vendor name, add a colon, then specify the jdk version:

Oracle Corporation:21.0.1+12-29

4. Use java

java -version
echo $JAVA_HOME

5. The cd command and JAVA_HOME

For bash|zsh|powershell, the cd command is replaced with a convenient function: cdjh
it will cd into the specified directory, and configure JAVA_HOME environment variable automatically.

You could also instead explicitly call the cdjh function.

Note: This feature is not provided for cmd, you have to set it manually by executing the following command:

for /f "delims=" %%i in ('jdkman which') do set "JAVA_HOME=%%i"

How to build

1. Prerequisites

  • JDK 21
  • GraalVM Native Image for JDK 21

To build jdkman-proxy, you will need rust|cargo.
It's already built and placed in resource folder, so you can skip rust.

2. Build

Linux or macOS

./gradlew clean shadowJar
native-image \
	--enable-preview \
	-jar build/libs/jdkman.jar \
	-Ob -march=compatibility \
	--no-fallback \
	-o jdkman

Windows (using powershell)

# build `jdkman-proxy`
$arch="x86_64" # change to aarch64 if running arm windows
cd .\src\main\rust\
cargo build --release
Copy-Item .\target\release\jdkman-proxy.exe ..\resources\io\vproxy\jdkman\res\jdkman_proxy-windows-$arch.exe
cd ..\..\..\

# build jdkman
.\gradlew.bat clean shadowJar
native-image `
	--enable-preview `
	-jar build\libs\jdkman.jar `
	--features=io.vproxy.jdkman.res.Feature `
	--static `
	-Ob -march=compatibility `
	--no-fallback `
	-o jdkman

Linux static image in docker

You can build a linux static native image using vproxyio/graalvm-jdk-21

docker run --name jdkman-build -it -v `pwd`:/workdir vproxyio/graalvm-jdk-21 /bin/bash
## inside docker
./gradlew clean shadowJar
LIBC="musl" ## or glibc
native-image \
	--enable-preview \
	-jar build/libs/jdkman.jar \
	--static --libc=$LIBC \
	-Ob -march=compatibility \
	--no-fallback \
	-o jdkman

jdkman's People

Contributors

wkgcass avatar

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.