cross platform java_jabba: (cross-platform) Java Version Manager

jabba

latest-0.7.0-blue.svgjabba.svg?branch=master

d96d3c1ba577f9862c39805b761a917a.png

Java Version Manager inspired by nvm (Node.js) / rvm (Ruby).

Supports installation of Oracle JDK (default) / Server JRE,

Zulu OpenJDK (since 0.3.0), IBM SDK, Java Technology Edition (since 0.6.0) and from custom URLs.

It's written in Go to make maintenance easier (significantly shorter, easier to understand and less prone to errors

compared to pure shell implementation). Plus it enables us to support Windows natively (no need for Cygwin) without rewriting

the whole thing in PowerShell or whatever.

The goal is to provide unified pain-free experience of installing (and switching between different versions of) JDK regardless of

the OS.

jabba has a single responsibility - managing different versions of JDK. For an easy way to install Scala/Kotlin/Groovy (+ a lot more) see SDKMAN.

SBT/Maven/Gradle should ideally be "fixed in place" by sbt-launcher/mvnw/gradlew.

Installation

macOS / Linux

(in bash/zsh/...)

curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh

(use the same command to upgrade)

In fish command looks a little bit different -

curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash; and . ~/.jabba/jabba.fish

If you don't have curl installed - replace curl -sL with wget -qO-.

If you are behind a proxy see -

curl /

wget manpage.

Usually simple http_proxy=http://proxy-server:port https_proxy=http://proxy-server:port curl -sL ... is enough.

Docker

While you can obviously use the same snippet as above, chances are you don't want jabba binary & shell

integration script(s) to be included in the final Docker image, all you want is a JDK. In this case

use the following Dockerfile (this is just an example; adjust if needed) (when JABBA_COMMAND env variable is set

install.sh downloads jabba binary, executes specified command and then deletes the binary)

FROMbuildpack-deps:jessie-curl

# Server JRE (https://goo.gl/2MsPoh)

ENVJAVA_VERSION "sjre@1.8.121"

RUNcurl -sL https://github.com/shyiko/jabba/raw/master/install.sh | \

JABBA_COMMAND="install$JAVA_VERSION" bash

ENVJAVA_HOME /root/.jabba/jdk/$JAVA_VERSION

ENVPATH $JAVA_HOME/bin:$PATH

(build & run as usual)

$docker build -t sjre:1.8.121 .

$docker run -it --rm sjre:1.8.121 java -version

java version "1.8.0_121"

Java(TM) SE Runtime Environment (build 1.8.0_121-b13)

Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Windows 10

(in powershell)

Invoke-Expression(

wgethttps://github.com/shyiko/jabba/raw/master/install.ps1-UseBasicParsing

).Content

(use the same command to upgrade)

Usage

# install Oracle JDK

jabba install1.8 # "jabba use 1.8" will be called automatically

# install Zulu OpenJDK (since 0.3.0)

jabba installzulu@1.8.72

# install IBM SDK, Java Technology Edition (since 0.6.0)

jabba installibm@1.8.0-3.21

# install from custom URL (supported qualifiers: zip (since 0.3.0), tgz, dmg, bin)

jabba install1.8.0-custom=tgz+http://example.com/distribution.tar.gz

jabba install1.8.0-custom=zip+file:///opt/distribution.zip

# link system JDK

jabba linksystem@1.8.72 /Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk

# list all installed JDK's

jabba ls

# switch to a different version of JDK

jabba use 1.6.65

echo "1.8" > .jabbarc

# switch to the JDK specified in .jabbarc (since 0.5.0)

jabba use

# list available JDK's

jabba ls-remote

# set default java version on shell (since 0.2.0)

# this version will automatically be "jabba use"d every time you open up a new terminal

jabba aliasdefault 1.6.65

.jabbarc has to be a valid YAML file. JDK version can be specified as jdk: 1.8 or simply as 1.8

(same as ~1.8, 1.8.x ">=1.8.0 <1.9.0" (mind the quotes)).

jsyk: jabba keeps everything under ~/.jabba (on Linux/Mac OS X) / %USERPROFILE%/.jabba (on Windows). If at any point of time you decide to uninstall jabba - just remove this directory.

For more information see jabba --help.

Development

PREREQUISITE: go1.8

git clone https://github.com/shyiko/jabba $GOPATH/src/github.com/shyiko/jabba

cd $GOPATH/src/github.com/shyiko/jabba

make fetch

go run jabba.go

# to test a change

make test # or "test-coverage" if you want to get a coverage breakdown

# to make a build

make build # or "build-release" (latter is cross-compiling jabba to different OSs/ARCHs)

FAQ

Q: What if I already have java installed?

A: It's fine. You can switch between system JDK and jabba-provided one whenever you feel like it (jabba use ... / jabba deactivate).

They are not gonna conflict with each other.

Q: How do I switch java globally?

A: jabba doesn't have this functionality built-in because the exact way varies greatly between the operation systems and usually

involves elevated permissions. But. Here are the snippets that should work:

Windows

(in powershell as administrator)

# select jdk

jabba use ...

# modify global PATH & JAVA_HOME

$envRegKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', $true)

$envPath=$envRegKey.GetValue('Path', $null, "DoNotExpandEnvironmentNames").replace('%JAVA_HOME%\bin;', '')

[Environment]::SetEnvironmentVariable('JAVA_HOME', "$(jabba which $(jabba current))", 'Machine')

[Environment]::SetEnvironmentVariable('PATH', "%JAVA_HOME%\bin;$envPath", 'Machine')

Linux

(tested on Debian/Ubuntu)

# select jdk

jabba use ...

sudo update-alternatives --install /usr/bin/java java ${JAVA_HOME%*/}/bin/java 20000

sudo update-alternatives --install /usr/bin/javac javac ${JAVA_HOME%*/}/bin/javac 20000

To switch between multiple GLOBAL alternatives use sudo update-alternatives --config java.

License

By using this software you agree to

This software is for educational purposes only.

Use it at your own risk.

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值