Manage your Java environment
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Tomasz "LAFK_pl" Borek 4b5b800a22 Bold doesn't work in Markdown if you use too many spaces - corrected formatting 8 years ago
available-plugins Don't run jenv javahome twice 9 years ago
bin add support for mvn, gradle and ant 13 years ago
completions Removing trailing slashes as explained here: http://superuser.com/questions/564716/bash-completion-for-filename-patterns-or-directories 12 years ago
fish Provides the export function 12 years ago
libexec #181 Support --skip-existing in jenv-add 8 years ago
LICENSE fix 13 years ago
README.md Bold doesn't work in Markdown if you use too many spaces - corrected formatting 8 years ago

README.md

Why this fork?

In no particular order.

  1. Cause I have some free time
  2. Cause I want to clean up jenv.be repo
  3. Cause bad English is bad
  4. Cause Zulu is not recognized now.

I've pulled in some PRs from others, and will maintain it for some time, till @gcuisinier will merge them or drop the thing entirely. I'm yet to announce to him what I'm doing and why, first I want to do it. :-)

Master your Java Environment with jenv

Website : http://www.jenv.be

Flattr this git repo

jenv is equivalent to rbenv, but for Java environments. It allows you to easily switch between several JDKs installations (already present), and configure which one to use per project.

jEnv may work on bash-ready OS.

Verified on :

  • Mac OS X
  • Debian

Gettings started

  1. Check out jenv into ~/.jenv.
$ git clone https://github.com/gcuisinier/jenv.git ~/.jenv
  1. Add ~/.jenv/bin to your $PATH for access to the jenv command-line utility.
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile

Ubuntu note: Modify your ~/.profile instead of ~/.bash_profile.

Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile.

Fish note: Modify your `~/.conf/fish/config.sh' to append

set PATH $HOME/.jenv/bin $PATH
  1. Add jenv init to your shell to enable shims and autocompletion.
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile

Same as in previous step, use ~/.profile on Ubuntu, ~/.zshrc for Zsh.

Fish note: Instead, copy ~/.jenv/fish/jenv.fish to ~/.conf/fish/function/jenv.fish. If you don't have the export function, also copy export.fish

cp ~/.jenv/fish/jenv.fish ~/.conf/fish/function/jenv.fish
cp ~/.jenv/fish/export.fish ~/.conf/fish/function/export.fish
  1. Restart your shell as a login shell so the path changes take effect. You can now begin using jenv.
$ exec $SHELL -l
  1. Configure JVM in jenv
$ jenv add /path/to/java/home
  1. Configure which JVM to use (globally, by directory, or for the current shell instance)
$ jenv global oracle-1.7.0

or

 $ jenv local oracle-1.7.0

or

 $ jenv shell oracle-1.7.0
  1. Check that works
 $ java -version
  1. Add JVM Options (globally, by directory or for the current shell instance)
$ jenv global-options "-Xmx512m"

or

 $ jenv local-options "-Xmx512m"

or

 $ jenv shell-options "-Xmx512m"
  1. Check that works
 $ jenv info java
  1. jenv also provides wrappers for several build tools (Ant, Gradle, Maven, SBT) that will use the configured JVM Options (globally, by directory or for the current shell instance), unless the tool's environment variable is already set (e.g. ANT_OPTS for Ant).

Command Reference

Like git, the jenv command delegates to subcommands based on its first argument. The most common subcommands are:

jenv local

Sets a local application-specific Java version by writing the version name to a .java-version file in the current directory. This version overrides the global version, and can be overridden itself by setting the JENV_VERSION environment variable or with the jenv shell command.

$ jenv local oracle-1.7

When run without a version number, jenv local reports the currently configured local version. You can also unset the local version:

$ jenv local --unset

Previous versions of jenv stored local version specifications in a file named .jenv-version. For backwards compatibility, jenv will read a local version specified in an .jenv-version file, but a .java-version file in the same directory will take precedence.

jenv global

Sets the global version of Java to be used in all shells by writing the version name to the ~/.jenv/version file. This version can be overridden by an application-specific .java-version file, or by setting the JENV_VERSION environment variable.

$ jenv global oracle-1.6

The special version name system tells jenv to use the system Java (detected by searching your $PATH).

When run without a version number, jenv global reports the currently configured global version.

jenv shell

Sets a shell-specific Java version by setting the JENV_VERSION environment variable in your shell. This version overrides application-specific versions and the global version.

$ jenv shell jJava-1.7.1

When run without a version number, jenv shell reports the current value of JENV_VERSION. You can also unset the shell version:

$ jenv shell --unset

Note that you'll need jenv's shell integration enabled (step 3 of the installation instructions) in order to use this command. If you prefer not to use shell integration, you may simply set the JENV_VERSION variable yourself:

$ export JENV_VERSION=oracle-1.6

jenv versions

Lists all Java versions known to jenv, and shows an asterisk next to the currently active version.

$ jenv versions
  oracle-1.6
*  oracle-1.7 (set by /Users/hikage/.jenv/version)

jenv version

Displays the currently active Java version, along with information on how it was set.

$ jenv version
oracle-1.6 (set by /tmp/test/.java-version)

jenv rehash

Installs shims for all Java executables known to jenv (i.e., ~/.jenv/versions/*/bin/*). Run this command after you install a new version of Java.

$ jenv rehash

jenv which

Displays the full path to the executable that jenv will invoke when you run the given command.

$ jenv which java
/Users/sam/.jenv/versions/oracle-1.6/bin/java

jenv whence

Lists all Java versions with the given command installed.

$ jenv whence java
oracle-1.6
oracle-1.7

Plugins

Jenv provides plugins to make command-line tools aware of which JDK is activated.

$ jenv plugins
ant
golo
gradle
grails
groovy
lein
maven
sbt
scala
vlt

Let's say you want Maven to use the JDK activated with Jenv, not the default JAVA_HOME configuration. You need to activate Jenv's maven plugin.

$ jenv enable-plugin maven
maven plugin activated

$ jenv disable-plugin maven
maven disabled

Note: The enable-plugin functionality is system wide not local to the shell, or temporary - you only need to do each one once.

Export plugin

Another one usefull plugin is the "export", that expose JAVA_HOME automatically :

$ jenv enable-plugin export
  You may restart your session to activate jenv export plugin echo export plugin activated

Development

The jenv source code is hosted on GitHub. It's clean, modular, and easy to understand, even if you're not a shell hacker.

It is based on rbenv.

Please feel free to submit pull requests and file bugs on the issue tracker.

Version History