English 中文(简体)
JVM version manager
原标题:
  • 时间:2010-03-17 16:18:50
  •  标签:
  • java
  • jvm
  • rvm

Is there Ruby Version Manager equivalent for the Java world?

I m looking for tool which allow me to easily download and install a new JVMs and switch between them. For example:

jvm install <version>
jvm list //will list installed JVMs on my system
jvm use jdk1.6 //will switch my env to jdk 1.6 version, etc.
最佳回答

If you use Ubuntu you can specify which JVM you want to use via command (works only for JVM installed from apt-get or aptitude)

sudo update-alternatives --config java

Or by setting JAVA_HOME. Here is good tutorial:

http://vietpad.sourceforge.net/javaonlinux.html

问题回答

http://www.jenv.be/ will allow this type of control.

SDKMAN! is a similar tool for the Java ecosystem. Supports various Java versions, Scala, Clojure, Kotlin, Groovy, and build tools like Maven and Gradle.

Works on Mac and Linux, with some mentions of support for Windows depending on how hard you are willing to try :)

For the sake of completeness, there are two more - jabba (of which I am the author; written in Go and designed after nvm/gvm/rvm)
and jenv (not to confuse with jenv.be; doesn t support installation from oracle but can install from a custom zip).

As it is not (yet) in the list of possibilities, there s also asdf.
asdf does not only provide version management for java, it has plugins for ~400 different languages and tools by default, you can find more on github, or create your own.

Here is an example how to setup a new install (you can also install completion so you don t have to list the versions first). The java plugin is added, a specific version (there are versions for adoptopenjdk, corretto, dragonwell, graalvm, liberica, mandrel, microsoft, openjdk, oracle, sapmachine, semeru, temurin, trava, zulu) is installed and configured to be the global (or local version) to use:

asdf plugin-add java                # Add java Plugin
asdf list-all java                  # List all available java versions
asdf install java temurin-20.0.1+9  # Install specific jdk version
asdf install java temurin-17.0.7+7  # Install another jdk version
asdf global java temurin-17.0.7+7   # Set the global jdk version
asdf local java temurin-20.0.1+9    # Set the local version for calls from the current directory

asdf uses a file in $HOME/.tool-versions to configure the global selected version. If you call any tool in a directory that has a .tool-versions file with a different version, that one is used (defined with asdf local …).

With JVMs, if you need to switch between them you just need to use a batch file (or powershell script) to manage the classpath and JVM path. You don t need to rely on the system default JVM path and instead just allow your app to point to whatever JVM you like by changing classpath and JVM path environment in the shell that runs the JVM.

For programs that are getting Java location from the Registry, in theory you could use a batch script to update that also.

In this respect Java is way easier than "Ruby version manager".

The trick is to use update-java-alternatives (from the java-common package). The update-alternatives command will not update every one of the symbolic links for various java /bin executables, which is why update-java-alternatives is better.

So to go for OpenJDK 6 to 7, use update-java-alternatives -l to get a list of Java alternatives and then used sudo update-java-alternatives -s java-1.7.0-openjdk-amd64 to switch the JDK.

CAVEAT: The command above might throw the following errors,

update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-java-alternatives: plugin alternative does not exist: 
  /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so

This is because the openjdk plugin is not installed by default. To fix run sudo apt-get install icedtea-7-plugin and rerun update-java-alternatives.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签