Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 873
James McMahon Avatar asked Feb 19 '23 01:02

James McMahon


2 Answers

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;

  • use the external compiler by adding something like "compile.using(:externaljavac)" into your buildfile.
  • use JRuby.

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
like image 62
Peter Donald Avatar answered Mar 05 '23 04:03

Peter Donald


This isn't so much of an answer as it is a work around. I got the build to work, but only after I installed and used JRuby instead of Ruby (CRuby? I am more of a Python guy).

From my research it seems like the 1.7 JVM causes a lot of problems under Mac OS X. Eclipse seems to suffer from a very similar problem where the platform won't start using the JVM specific in Java Preferences and in JAVA_HOME. Hopefully at some point these issues will be resolved, but for now it seems like JRuby is a good workaround.

TLDR; use JRuby.

like image 21
James McMahon Avatar answered Mar 05 '23 04:03

James McMahon