Skip to Content

How I deal with multiple versions of java with Pacifist and Jenv

I’ve been trying to develop with solely Java 8 for more than a year now. However, most of the projects I worked with were still Java 7. Here’s how I setup my machine with multiple versions of Java. Be warned that the whole process is not up to my automation standards. There are a lot of manual steps. But I couldn’t find a better setup. Maybe you can help me.

OSX is well known for installing new versions of Java is some secret, changed every once in a while, place. I don’t like that.

I use Pacifist to install java where ever I want. I choose ~/java/ but you can pick whichever folder you want. That’s a plus side of the method. The downside is that the process is manual.

Here’s the standard procedure: download java, open the .pkg with Pacifist, locate Home folder inside package’s hierarchy. Extract the Home folder into ~/java/. Uncheck the Use administrator privileges, it’s not needed. At last, rename ~/java/Home to the name of the jdk. ~/java/jdk8u5 for example.

It would be great to use a command-line tool to download and unzip the whole thing to the right place. Shouldn’t be too hard to do. If someone has time…

Don’t forget to configure this jdk in IntelliJ. I use the same name I used for the folder. Consistency matters.

I’d love to configure IntelliJ just once. Tell it where you put your jdks and let the tool deal with it. Maybe one day…

I use jenv to switch java depending on the folder I work in. Jenv lets me register each jdk under a different name with jenv add command. I use the same names as the ones I used during the Pacifist step.

Jenv is helpful to register the jdk but it will give a very bad name to it. You have to rename some jenv files manually. A jenv add path name command would be nicer.

What would be even nicer is to configure jenv only once with the folder where I put all my jdks and let it find out which versions are available.

Maybe jenv could also take care of the download like rbenv does for Ruby (if I remember correctly).

Anyway, there’s a lot to improve here, but it’s nice to type mvn install or java inside a folder and let jenv pick the right version of the jdk.

comments powered by Disqus