Forum: JRuby Compile ruby files (.rb) to .class files which are compatible with older Java versions

D494f5e1ac7a789670314adb451e7f80?d=identicon&s=25 Artis Abolts (aboltart)
on 2014-03-03 08:16
In JRuby wiki page (https://github.com/jruby/jruby/wiki/JRubyCompiler)
is described how to compile ruby files (.rb) to .class files

Is there any possibility to specify some flags in order to to generate
class files which are compatible with older Java versions?

Like compiling java files to .class file
javac -source 1.4 HelloWorld.java
Caa2df9372ffa0a9e95b2bab1e8fea34?d=identicon&s=25 Karol Bucek (Guest)
on 2014-03-03 18:29
(Received via mailing list)
-J prefixed options should be passed to javac ... e.g. jrubyc -J-target
1.5
hello_world.rb

JRuby needs 1.6 at minimum you won't be able to compile for 1.4 ... well
you might be but it won't run.

K.
D494f5e1ac7a789670314adb451e7f80?d=identicon&s=25 Artis Abolts (aboltart)
on 2014-03-04 07:54
Karol Bucek wrote in post #1138660:
> -J prefixed options should be passed to javac ... e.g. jrubyc -J-target
> 1.5
> hello_world.rb
>
> JRuby needs 1.6 at minimum you won't be able to compile for 1.4 ... well
> you might be but it won't run.
>
> K.

Thanks for replay, but somehow this solution not works :(
On my local machine I have "1.7" Java, on client machine is "1.6" Java.
Before deploy locally I am compiling all ruby files.

I run multiple tests by compiling Ruby file using jrubyc command. One
time I passed -J-target 1.6 option, other time I used -J-source 1.6
option

Both time when I deployed code on machine where is "1.6" Java I got
following error message by application startup

java.lang.UnsupportedClassVersionError: app/models/foo : Unsupported
major.minor version 51.0

I checked JRuby source code
https://github.com/jruby/jruby/blob/b8f834c9e1ddc0...

Yes, jrubyc command is accepting -J options for which will be passed to
javac, but seams that these options are used only if is passed javac
option which will generate from .rb files .java files


Only solution what worked for me was install second Java (1.6) on local
machine, and by compiling use 1.6 Java

Artis
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.