macosbuildjavacjavabuildr

Buildr complaining about javac: invalid source release: 1.7


I am having an issue with Apache's Buildr complaining about an invalid source release. Whenever I try and build my project I get the following error message;

javac: invalid source release: 1.7
Usage: javac <options> <source files>
use -help for a list of possible options
Buildr aborted!
RuntimeError : Failed to compile, see errors above

One would assume I don't have Java 7 installed on my system, but when I execute javac -version I get javac 1.7.0-u10-b08, which is the OpenJDK I just installed.

What is going on here? My first guess would be that Buildr is running the wrong version of Java but I have no idea how to fix or confirm that.

To give some background to this question, I am running Mac OS X version 8 (Mountain Lion) and have installed the OpenJDK from http://code.google.com/p/openjdk-osx-build/. I am using RVM to manage Ruby and installed Buildr using env JAVA_HOME=$JAVA_HOME gem install buildr as recommend in the documentation. My JAVA_HOME is set to /Library/Java/JavaVirtualMachines/1.7.0u.jdk/Contents/Home, which is where I installed the OpenJDK.

If anyone could help me here I would really appreciate it.

UPDATE: It really looks like Buildr is just not respecting my JAVA_HOME. I went in and unchecked the system version (version 6) of Java in the Java Preferences and now I get a different error,

JavaVM: requested Java version ((null)) not available. Using Java at "" instead.
JavaVM: Failed to load JVM: /bundle/Libraries/libserver.dylib
JavaVM FATAL: Failed to load the jvm library.
Buildr aborted!
RuntimeError : can't create Java VM

Solution

  • I had a look at this and it looks to be a bug somehow related to the way that RJB on OSX works. RJB is the library that Buildr uses to interact with the JVM. Essentially RJB does not seem to allow the configuration of the JVM without setting some environment variables (possibly at build time?). See http://rjb.rubyforge.org/.

    There are two main ways to work around this;

    I will look into what is required to solve this correctly for the next release (1.4.8).

    Update

    Fixed in 1.4.8 - a work around for 1.4.7 is to set the JVM_LIB environment variable like

    export JVM_LIB=$JAVA_HOME/jre/lib/server/libjvm.dylib