linux-china / jenv

Java enVironment Manager
http://jenv.io
Apache License 2.0
602 stars 82 forks source link

jenv: the Java enVironment Manager

Join the chat at https://gitter.im/linux-china/jenv jenv is a tool for managing parallel Versions of Java Development Kits on any system, such as Linux, Mac and Windows. It provides a convenient command line interface for installing, switching, removing and listing candidates. If you have any problem, please join gitter room: https://gitter.im/linux-china/jenv

Why jenv

Installat jenv

Open your favourite terminal and enter the following:

    $ curl -L -s get.jenv.mvnsearch.org | bash

If the environment needs tweaking for jenv to be installed, the installer will prompt you accordingly and ask you to restart.

Install Java

Because I cannot redistribute Java SDK, so you should download it from http://www.oracle.com/technetwork/java/javase/downloads/index.html and install by yourself. After installation, please execute the following command:

    $ mkdir -p $HOME/.jenv/candidates/java
    $ ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/home $HOME/.jenv/candidates/java/1.8.0_112
    $ jenv default java 1.8.0_112

for Mac user, after you install JDK from dmg file, please execute:

$ jenv install java 1.8.0_112 system

and jenv will link the Java version automatically.

You can also install Java by http url:

$ jenv install java 1.8.0_112 http://xxxx.com/java/java-1.8.0_112.zip

Install candidates

Firstly, view all available candidates:

$ jenv all

Secondly, list available versions for the candidate, such as maven candidate:

$ jenv ls maven

Finally, install the candidate with the specified version:

$ jenv install maven 3.5.3

In your terminal, type mvn --version to check the installation.

If you want to list all installed candidates, use the following command:

$ jenv ls

For Docker user, your can use silent mode in your Dockerfile as following:

$ JENV_AUTO=true; jenv install maven 3.5.3

Update repository

The candidate's versions are maintained in the central repository. To keep updated with central repository, please use:

$ jenv repo update

Clonable development environments with jenv

You can clone your jenv between multiple hosts.

Other Commands

jenvrc support

jenvrc is jenv setup file which contains candidate and the version as following:

java=1.8.0_112
maven=3.5.3

After you enter this directory, jenv will setup environment automatically. Now You can use jenvrc to setup Java environment for each of your individual projects. You can use jenv init to generate jenvrc file.

  $jenv init

Note: Line started with # means line comment.

Script Hook

All the scripts are under candidate home and invoked by jenv automatically.

Install local candidates

If you want to add custom candidate into jenv, please create candidates_local under $HOME/.jenv/db/ directory and input candidate name.

$jenv add spike 0.0.1
$jenv install spike 0.0.1 git@github.com:linux-china/groovy_scripts.git

Then you can install candidate from git repository, and you can update candidate by following command:

$jenv update spike

If the candidate is absent, jenv will update all git or svn based candidates.

$jenv update

Update all git or svn based candidates.

jenv with Docker Executable Images

If you want to integrate jenv with Docker Executable Images, you can use following steps:

How to update jenv

Please use selfupdate command to get last version and candidate repository.

   $ jenv selfupdate

jenv IntelliJ IDEA plugin

With jenv IDEA plugin, you don't need to setup Java SDK, Maven, and so on, and jenv IDEA plugin can scan jenv directory and setup the settings in IDEA automatically. Please visit http://plugins.jetbrains.com/plugin/?idea&pluginId=7229

Reference

TODO