GithubHelp home page GithubHelp logo

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

Stargazers

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

Watchers

 avatar  avatar

jdkman's Issues

部分程序提示无法找到 javaw.exe

你好,使用jdkman后其他正常,但是 使用 spoon工具时,打开spoon.bat 会提示找不到 javaw.exe
image

下面是spoon.bat程序自带的bat脚本的内容:

`
@echo off

REM *****************************************************************************
REM
REM Pentaho Data Integration
REM
REM Copyright (C) 2005 - 2022 by Hitachi Vantara : http://www.hitachivantara.com
REM
REM *****************************************************************************
REM
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with
REM the License. You may obtain a copy of the License at
REM
REM http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.
REM
REM *****************************************************************************

setlocal

cd /D %~dp0

REM **************************************************
REM ** Set console window properties **
REM **************************************************
REM TITLE Spoon console
REM COLOR F0

:: **************************************************
:: ** Kettle home **
:: **************************************************

if "%KETTLE_DIR%"=="" set KETTLE_DIR=%dp0
if %KETTLE_DIR:
-1%==\ set KETTLE_DIR=%KETTLE_DIR:~0,-1%

cd %KETTLE_DIR%

REM Special console/debug options when called from SpoonConsole.bat or SpoonDebug.bat
if "%SPOON_CONSOLE%"=="1" set PENTAHO_JAVA=java.exe
if not "%SPOON_CONSOLE%"=="1" set PENTAHO_JAVA=javaw.exe
set IS64BITJAVA=0

call "%~dp0set-pentaho-env.bat"

REM **************************************************
REM Platform Specific SWT **
REM **************************************************

REM The following line is predicated on the 64-bit Sun
REM java output from -version which
REM looks like this (at the time of this writing):
REM
REM java version "1.6.0_17"
REM Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
REM Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)
REM
REM Below is a logic to find the directory where java can found. We will
REM temporarily change the directory to that folder where we can run java there
pushd "%_PENTAHO_JAVA_HOME%"
if exist java.exe goto USEJAVAFROMPENTAHOJAVAHOME
cd bin
if exist java.exe goto USEJAVAFROMPENTAHOJAVAHOME
popd
pushd "%_PENTAHO_JAVA_HOME%\jre\bin"
if exist java.exe goto USEJAVAFROMPATH
goto USEJAVAFROMPATH
:USEJAVAFROMPENTAHOJAVAHOME
FOR /F %%a IN ('.\java.exe -version 2^>^&1^|%windir%\system32\find /C "64-Bit"') DO (SET /a IS64BITJAVA=%%a)
FOR /F %%a IN ('.\java.exe -version 2^>^&1^|%windir%\system32\find /C "version ""1.8."') DO (SET /a ISJAVA8=%%a)
GOTO CHECK32VS64BITJAVA
:USEJAVAFROMPATH
FOR /F %%a IN ('java -version 2^>^&1^|%windir%\system32\find /C "64-Bit"') DO (SET /a IS64BITJAVA=%%a)
FOR /F %%a IN ('java -version 2^>^&1^|%windir%\system32\find /C "version ""1.8."') DO (SET /a ISJAVA8=%%a)
GOTO CHECK32VS64BITJAVA
:CHECK32VS64BITJAVA

IF %IS64BITJAVA% == 1 GOTO :USE64

:USE32
REM ===========================================
REM Using 32bit Java, so include 32bit SWT Jar
REM ===========================================
set LIBSPATH=libswt\win32
GOTO :CONTINUE
:USE64
REM ===========================================
REM Using 64bit java, so include 64bit SWT Jar
REM ===========================================
set LIBSPATH=libswt\win64
set SWTJAR=..\libswt\win64
:CONTINUE
popd

REM **************************************************
REM ** Setup Karaf endorsed libraries directory **
REM **************************************************
set JAVA_ENDORSED_DIRS=
set JAVA_LOCALE_COMPAT=
set JAVA_ADD_OPENS=
IF NOT %ISJAVA8% == 1 GOTO :SKIPENDORSEDJARS

if not "%_PENTAHO_JAVA_HOME%" == "" set JAVA_ENDORSED_DIRS=%_PENTAHO_JAVA_HOME%\jre\lib\endorsed;%_PENTAHO_JAVA_HOME%\lib\endorsed;
set JAVA_ENDORSED_DIRS="-Djava.endorsed.dirs=%JAVA_ENDORSED_DIRS%%KETTLE_DIR%\system\karaf\lib\endorsed"
GOTO :COLLECTARGUMENTS

:SKIPENDORSEDJARS
REM required for Java 11 date/time formatting backwards compatibility
set JAVA_LOCALE_COMPAT=-Djava.locale.providers=COMPAT,SPI
set JAVA_ADD_OPENS=--add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/sun.net.www.protocol.jar=ALL-UNNAMED

:COLLECTARGUMENTS
REM **********************
REM Collect arguments
REM **********************

set _cmdline=
:TopArg
if %1!==! goto EndArg
set _cmdline=%_cmdline% %1
shift
goto TopArg
:EndArg

REM ******************************************************************
REM ** Set java runtime options **
REM ** Change 2048m to higher values in case you run out of memory **
REM ** or set the PENTAHO_DI_JAVA_OPTIONS environment variable **
REM ******************************************************************

if "%PENTAHO_DI_JAVA_OPTIONS%"=="" set PENTAHO_DI_JAVA_OPTIONS="-Xms1024m" "-Xmx2048m"

set OPT=%OPT% %PENTAHO_DI_JAVA_OPTIONS% "-Djava.library.path=%LIBSPATH%;%HADOOP_HOME%/bin" %JAVA_ENDORSED_DIRS% %JAVA_LOCALE_COMPAT% "-DKETTLE_HOME=%KETTLE_HOME%" "-DKETTLE_REPOSITORY=%KETTLE_REPOSITORY%" "-DKETTLE_USER=%KETTLE_USER%" "-DKETTLE_PASSWORD=%KETTLE_PASSWORD%" "-DKETTLE_PLUGIN_PACKAGES=%KETTLE_PLUGIN_PACKAGES%" "-DKETTLE_LOG_SIZE_LIMIT=%KETTLE_LOG_SIZE_LIMIT%" "-DKETTLE_JNDI_ROOT=%KETTLE_JNDI_ROOT%"

REM ***************
REM ** Run... **
REM ***************

if %STARTTITLE%!==! SET STARTTITLE="Spoon"
REM Eventually call java instead of javaw and do not run in a separate window
if not "%SPOON_CONSOLE%"=="1" set SPOON_START_OPTION=start %STARTTITLE%

@echo on
%SPOON_START_OPTION% "%_PENTAHO_JAVA%" %JAVA_ADD_OPENS% %OPT% -jar launcher\launcher.jar -lib ..%LIBSPATH% %_cmdline%
@echo off
if "%SPOON_PAUSE%"=="1" pause
`

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.