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

In JRuby wiki page (JRubyCompiler · jruby/jruby Wiki · GitHub)
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

-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.

Karol B. 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 :frowning:
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

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