[英]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. 我可以在“ Scala Project”中以.java
文件为主要对象来运行三个世界。 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". 问题是,尽管我的“ Scala项目”中有JRE系统库,但它是从我未使用的“ Java项目”中提取的。 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. 我将jar安排为Scala库,JRE库和JRuby Jar的引用库。 I also have the same in the "Java Project" that I don't want to use. 我也不想在“ Java项目”中使用相同的内容。 If I close that project, this project, "Scala Project" fails to run. 如果我关闭该项目,则该项目“ Scala项目”将无法运行。 Obviously this is not an important project, but I am wanting to better understand how this works. 显然,这不是一个重要的项目,但是我想更好地了解它是如何工作的。
There should be no problems using Java code inside of a Scala project. 在Scala项目中使用Java代码应该没有问题。 You must have inadvertently declared a dependency from the scala project to the Java project, but without more information, I can't tell. 您必须在无意中声明了从scala项目到Java项目的依赖关系,但是我没有更多的信息。
Please attach your .classpath and .project files for your scala project. 请为您的scala项目附加.classpath和.project文件。
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. 在om-nom-nom提供+50的答案之前,这个问题有一段时间没有激活。 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. 为了使该答案对其他人有意义,我在http://shaneofalltrades.com/java.html上创建了一个博客,其中包含有关完整设置的详细信息。 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. 如果您已经拥有Eclipse,则应该能够使用该版本,或者按照以下步骤操作并安装另一个Eclipse以使该环境独立。
Now we are going to take a break from Scala and download JRuby. 现在,我们将休息一下Scala并下载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. 如果您不希望使用Ruby,则可以跳过此步骤,也可以使用此步骤将JRuby添加到Java项目中。
That should cover everything for your Hello World of Java, Scala and Ruby. 这应该涵盖您的Java,Scala和Ruby Hello World的所有内容。 If you have any issues, please ask and I will be happy to help. 如果您有任何问题,请询问,我们将竭诚为您服务。
--- 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. Facets概念是正确的概念,但是目前Eclipse不以补充Facets的方式支持Web开发之外的核心IDE组件。
--- 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. 就您而言,我想您可能想将JRuby,Scala(和其他)添加到标准Java项目中。
--- Additional info after request --- ---根据要求提供其他信息---
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. 使用这种技术,您可以在Scala / JRuby / etc中添加其他帮助器。
I've mostly done this to tweak the web services side of the stack, so your mileage may vary. 我主要是通过调整堆栈中的Web服务来完成的,因此您的工作量可能会有所不同。 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. 但是,如果它不能像所宣传的那样正常工作,那么这是添加此类功能的正确方法,因此不要为发布错误感到害羞。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.