I was able to get all three running a Hello World in a “Scala Project” with a .java file as my main. The problem is that it is pulling from a “Java Project” I am not using, though I have the JRE System Library in my “Scala Project”. Here is the code as to what I am doing to help understand…
JRuby.java
import org.jruby.embed.ScriptingContainer;
public class JRuby {
public static void main(String[] args)
{
System.out.println("Java, Scala and Ruby using the JRE.\n");
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet("puts 'This is JRuby code in .java file!'");
new ScallaHello().hello();
System.out.println("This is standard Java Code in .java file!");
}
}
ScallaHello.scala
class ScallaHello {
def hello() {
println("This is a Scala Method in .scala file, object set in .java file")
}
System.out.println("This is Java Code in .scala file!")
println("This is Scalla Code in .scala file!")
}
End results are…
Java, Scala and Ruby using the JRE.
This is JRuby code in .java file!
This is Java Code in .scala file!
This is Scalla Code in .scala file!
This is a Scala Method in .scala file, object set in .java file
This is standard Java Code in .java file!
I have the jars organized as the Scala Library, JRE Library and Referenced Libraries for the JRuby Jar. I also have the same in the “Java Project” that I don’t want to use. If I close that project, this project, “Scala Project” fails to run. Obviously this is not an important project, but I am wanting to better understand how this works.
I ended up getting the issue corrected within the first week. This involved a dependency issue. I built a new project and it worked. This question was inactive for a while until om-nom-nom offered +50 for the answer. I am sorry if anyone felt there was still an answer needed. To make this answer resourceful to others, I have started a blog at http://shaneofalltrades.com/java.html with details on full set-up. Here is copy of that tutorial…
If you already have Eclipse, you should be able to use that version, or follow these steps and install another Eclipse to keep this environment separate.
Make sure you expand these and see all boxes, select ‘Select All’ then select Next>, select Next> again to install. Accept terms and select Finish. Make sure you go through terms that need to select and see all windows for this are selected. I ran into an issue downloading until I went through the checkboxes and “Accept Terms” more thoroughly. Once everything installs properly it should restart or ask for a restart.
Now Eclipse and Scala should be installed, but it still needs to be configured to work properly.
Now we are going to take a break from Scala and download JRuby. This step can be skipped if you don’t want Ruby, or you can use this a the only step to just add JRuby to a Java project.
Download JRuby
Back to configuring your project in Eclipse…
That should cover everything for your Hello World of Java, Scala and Ruby. If you have any issues, please ask and I will be happy to help.