Questions tagged [jruby-java-interop]

32 questions
12
votes
1 answer

Casting objects in JRuby

Is there a way I can explicitly cast one Java object to another Java class from JRuby? Sometimes I want to be able to invoke SomeJavaClass#aMethod(MySuperClass) rather than SomeJavaClass#aMethod(MyClass) from JRuby. From Java, I'd do…
rampion
  • 87,131
  • 49
  • 199
  • 315
8
votes
2 answers

Can I import Java class files into JRuby?

The documentation seems to suggest that in order for me to import Java classes into JRuby, that they must be in a JAR file: "In order to use resources within a jar file from JRuby the jar file must either be on the classpath or you can make it…
bjnortier
  • 2,008
  • 18
  • 18
7
votes
1 answer

Can you use gems, when you execute a Ruby script in embedded JRuby?

It so happened that I need to unit-test this Ruby script. It's a Sinatra-based web application that uses several gems. I have more experience in Java than in Ruby, time is very important (and elegance isn't), and so I thought I may be faster, if I…
Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
7
votes
0 answers

ScriptingContainer, Ruby Runtime and Variable Map

(Crossposting note: This question has also been posted at the JRuby mailing list (jruby@ruby-lang.org) on December 20 and on JRuby Forum on January 2nd, but hasn't got any response yet). This question is about understanding the impact of the…
user1934428
  • 19,864
  • 7
  • 42
  • 87
7
votes
3 answers

JRuby and Java objects

Please tell me if it is possible to do the following: create an instance of a specific class in Java pass it to JRuby to do something with it continue using the "modified" version in Java May you provide a small working example? EDIT: It turns out…
Geo
  • 93,257
  • 117
  • 344
  • 520
5
votes
1 answer

How do I correctly add to the CLASSPATH in a JRuby on Rails project?

I've added some external jars to my CLASSPATH by adding this in config/application.rb: require 'java' $CLASSPATH << "#{File.dirname(__FILE__)}/../backend/src/" Dir["#{File.dirname(__FILE__)}/../backend/lib/*.jar"].each do |jar| require…
Paul Biggar
  • 27,579
  • 21
  • 99
  • 152
5
votes
1 answer

The best source for reference information on Java interop with jRuby

What have you found as the best sources for jRuby interop syntax with Java? It took me forever yesterday to find something about adding to the classpath and the jruby.org site was not much help. Curious what references others use. Thanks.
Jed Schneider
  • 14,085
  • 4
  • 35
  • 46
4
votes
4 answers

Using Custom Java Class file in Jruby

I am trying to execute some custom Java code through the latest version of Jruby (1.5.1), Ruby 1.8.7, with Java 1.6.0_06. I have tried both the class file and putting it in a jar method. When I try require 'java' require…
holerd
  • 55
  • 1
  • 5
3
votes
1 answer

Why does my executable jar which loads jruby not run under a folder with spaces in its name eg Program files?

I have an executable jar that loads jruby. An installer drops the jar and some pre-packaged jar libraries (including complete jruby and some gems) into the install location. Everything works fine except in Windows when the jar is installed into a…
3
votes
2 answers

byte[] to RubyString for string xor in JRuby Java Extension

I'm trying to implement a Java extension for JRuby to perform string xors. I'm just uncertain how to type cast a byte array into a RubyString: public static RubyString xor(ThreadContext context, IRubyObject self, RubyString x, RubyString y) { …
fny
  • 31,255
  • 16
  • 96
  • 127
2
votes
1 answer

Java to JRuby to Resque

I have a hybrid web application which runs a Java WAR file and a JRuby WAR file in the same Tomcat. We have decided to use (JRuby) Resque as our job queue. The call to enqueue jobs looks like this: Resque.enqueue(FooWorker, 111) where FooWorker is…
Jay Godse
  • 15,163
  • 16
  • 84
  • 131
2
votes
0 answers

How do you generate Java method signatures that throw exceptions in JRuby? (i.e. to implement interfaces such as org.quartz.Job)

Given the following code: require 'java' java_import 'org.quartz.*' class RubyTestJob java_implements Java::org.quartz.Job java_signature 'void execute(org.quartz.JobExecutionContext jobExecutionContext) throws…
David W
  • 324
  • 1
  • 13
2
votes
1 answer

Plese help me understand JRuby method name conversion inconsistensies

Recently I've cobbled together a small project to play with JRuby and its interactions with Java. Here's the Github gist. LogicProcessor.java: package me.artsolopov.jrp; import javax.swing.*; import javax.swing.table.TableModel; import…
art-solopov
  • 4,289
  • 3
  • 25
  • 44
2
votes
1 answer

Java Reflection: Determining class of java.util.regex.Pattern in JRuby

Working on a legacy JRuby app (1.6.8) running under Java 11, I traced a peculiar error a test case: "require 'java'; puts java::util::regex::Pattern.class" errors ArgumentError: wrong number of arguments (0 for 1). For other built-in JRE classes,…
SRobertJames
  • 8,210
  • 14
  • 60
  • 107
2
votes
1 answer

How can I force JRuby to initialize a java ArrayList with java Longs instead of Fixnums?

Someone on my team is writing a ruby/cucumber test that calls a java api that takes a List argument. I'm trying to help him out but my jruby knowledge is pretty limited. Whenever the call to the java method that takes List is made the…
k s
  • 882
  • 8
  • 9
1
2 3