JRuby Warnings & Code Completion

Getting a bunch of warnings and limited code completion support when trying to write basic JRuby in RubyMine. The code runs correctly from the command line and from inside RubyMine.

require 'java'
java_import java.io.File


directory = File.new("/users/david")
files = directory.listFiles()

for file in files
    puts(file.getName())
end


Warnings
line 2: can't find java
line 6: cannot find listFiles for type File
line 9: cannot find getName


Versions
RubyMine 7.1.4
Java 1.8.0.20 (via jenv)
JRuby 9.0.0.0 (via rvm)
OSX 10.10.5

What is the current state of JRuby support in RubyMine or Intellij?

8 comments
Comment actions Permalink

Hi,

RubyMine is for Ruby development and thus it knows nothing about java :(  
It is better to use Idea + Ruby plugin for JRuby development.  If the problem is reproducible there then it is (most likely) a bug and we need to investigate/fix it.

Regards, Oleg.

0
Comment actions Permalink

Same thing is happening in Intellij 14.1.4. Project SDK is set to jruby-9.0.0.0. Project language level is SDK default (8 ...). Jruby is shown under the modules and facets settings.

0
Comment actions Permalink

Hello!

indeed there is a problem with getName, please vote for the corresponding issue:

https://youtrack.jetbrains.com/issue/RUBY-17120

Regarding another problems with resolution, have you added JDK in File | Project Structure | Platform Settings | SDKs?

0
Comment actions Permalink

Thanks for writing that up. Code completion seems to work OK once the project SDK is set to Java 8 and JRuby is set in the Modules and Facets settings.

0
Comment actions Permalink

I tried the same code above on ultimate edition of IntelliJ IDEA 14.1.4 with Ruby plugin. It urges me to use 'each' instead of for loop and 'getName' cannot be resolved.
Are there any basic guide or something to set up a project in Java and jruby? I am a beginner of Java and IDEs and found barrage of code inspection warnings saying methods implemented in Java are unresolved ?:|

0
Comment actions Permalink

'foreach' is proposed by inspection and inspired by https://github.com/roodi/roodi

As for 'getName', please vote and follow the corresponding issue: https://youtrack.jetbrains.com/issue/RUBY-17120

Regarding documentation, as we discussed before unfortunately we don't have it for this scenario, but we're planning to do it.

0
Comment actions Permalink
require 'java'
require 'jbundler'
require 'jruby/core_ext'
require 'bundler/setup'
Bundler.require

java_import 'ratpack.server.RatpackServer'


RatpackServer.start do |b|
b.handlers do |chain|
chain.get do |ctx|
ctx.render("Hello from Ratpack+JRuby and silly Charles")
end
end
end




Code above works, but IDEA complains that the java_import is using an incorrect jruby string import even though if I "un-string" it I get a runtime error stating that "ratpack" is not a message available on Object.
Also IDEA can't find RatpackServer and thus can't code complete against it.

0
Comment actions Permalink

@Charles,

thank you for the report, I've submitted the corresponding request on our tracker so please vote for it in order to be notified regarding its state:

https://youtrack.jetbrains.com/issue/RUBY-20341

0

Please sign in to leave a comment.