Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you open a single project for Java, Scala and JRuby in Eclipse?

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.

like image 785
Shane Avatar asked Jan 22 '12 20:01

Shane


2 Answers

There should be no problems using Java code inside of a Scala project. You must have inadvertently declared a dependency from the scala project to the Java project, but without more information, I can't tell.

Please attach your .classpath and .project files for your scala project.

like image 195
Andrew Eisenberg Avatar answered Oct 21 '22 14:10

Andrew Eisenberg


--- Edited as this answer is a dead end. ---

I'm leaving this posted so others don't attempt to go down this road. That said, it does not deserve any more up votes (but don't down vote it into oblivion either)

The Facets concept is the right concept, yet at this time Eclipse doesn't support core IDE components outside of web development in a manner that complements Facets.

--- Original post follows ---

Convert (or create) the project into a facets project. With facets you can add to (or remove) aspects of the default project nature. In your case, I would guess you would want to add JRuby, Scala, (and others) to a standard Java project.

--- Additional info after request ---

enter image description here Basically, you open up the project properties, then you select "Project Facets" from the left hand side, and select "convert project to facets form". Doing this will "unbundle" the facets of your "project nature" and allow you to add and remove individual project plugins. Using such techniques you may be able to add in your Scala / JRuby / etc additional helpers.

I've mostly done this to tweak the web services side of the stack, so your mileage may vary. However, if it doesn't work as advertised, this is the correct way to add in such functionality, so don't feel shy about posting a bug.

like image 36
Edwin Buck Avatar answered Oct 21 '22 14:10

Edwin Buck