简体   繁体   English

如何在Eclipse中为Java,Scala和JRuby打开单个项目?

[英]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以使该环境独立。

  1. Download Eclipse 3.7 Indigo from >>http://www.eclipse.org/downloads/ and choose the Eclipse IDE for Java Developers. 从>> http://www.eclipse.org/downloads/下载Eclipse 3.7 Indigo,然后选择Eclipse IDE for Java Developers。 Unzip in a folder easy for you to find. 解压缩文件夹,方便您查找。 If not familiar with Eclipse, it does not automatically load into your program files. 如果不熟悉Eclipse,它不会自动加载到您的程序文件中。 I placed mine in a documents folder. 我把我的放在文件文件夹中。 Once unzipped it is fully operational. 解压缩后即可完全使用。 You can pin the exceptional file to your task bar if easier for you. 如果方便,可以将例外文件固定到任务栏。
  2. Download scala-2.9.1.final.zip file for Eclipse at >>http://www.scala-lang.org/downloads Follow instructions. 在>> http://www.scala-lang.org/downloads下载适用于Eclipse的scala-2.9.1.final.zip文件。请按照说明进行操作。 At the time of this install, it involves pasting the download page/link into your Eclipse “Install New Software” section under the Help Tab in Eclipse. 在进行此安装时,它涉及将下载页面/链接粘贴到Eclipse中“帮助”选项卡下的Eclipse“安装新软件”部分。
  3. After pasting the link and naming your saved location, you should see the items… 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. 现在应该已经安装了Eclipse和Scala,但是仍然需要对其进行配置以使其正常工作。
  4. After Eclipse restarts, it should ask you if you want to check if plug-in settings are correct, select yes. Eclipse重新启动后,它会询问您是否要检查插件设置是否正确,请选择是。
  5. JDT Weaving should be enabled. 应启用JDT Weaving。 Select recommended default settings and select OK. 选择推荐的默认设置,然后选择确定。
  6. Now you should be able to select new project File>>New>Project… then select Scala Wizard>>Scala Project. 现在您应该能够选择新项目File >> New> Project…,然后选择Scala Wizard >> Scala Project。 Name your project then select next. 为您的项目命名,然后选择下一步。

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项目中。

Download JRuby 下载JRuby

  1. Go to http://jruby.org/download and download JRuby 1.6.6 Complete .jar 转到http://jruby.org/download并下载JRuby 1.6.6 Complete .jar
  2. Place file in location you will remember as you will have to access it in Eclipse in a couple steps from now. 将文件放置在您会记得的位置,因为从现在开始,您将需要在Eclipse中进行几个步骤的访问。
  3. Right click your Scala Package in the Package Explorer... 在Package Explorer中右键单击您的Scala Package ...
  4. Select Build Path, then select Add External Archives… Find your JRuby jar you just downloaded (placed in a safe folder before this step) and select it. 选择Build Path,然后选择Add External Archives…。找到您刚刚下载的JRuby jar(在此步骤之前放置在安全文件夹中)并选择它。 Eclipse will load this to your project along with your other Libraries. Eclipse会将其与其他库一起加载到您的项目中。 There might be a better way to include this with the JRE System Library as well that would eliminate this step. 也许还有更好的方法可以将其包含在JRE系统库中,从而省去了这一步骤。

Back to configuring your project in Eclipse… 返回在Eclipse中配置项目…

  1. Right click Scala Package again in the Package Explorer and select Build Path then select Configure Build Path…. 再次在Package Explorer中右键单击Scala Package,选择Build Path,然后选择Configure Build Path…。 Go to Order and Export tab and check mark all Libraries, then select OK. 转到“订单和导出”选项卡,并选中所有库,然后选择“确定”。
  2. Time To Build your project: Right Click Scala Package>>New>>Other… 是时候构建您的项目了:右键单击Scala Package >> New >> Other…
  3. Java>>Class, Select Next Java >>类,选择下一步
  4. Name it JRuby and check the boxes as this and select Finish… 将其命名为JRuby并选中复选框,然后选择Finish…
  5. Next create a Scala Class: Right Click Scala Package>>New>>Scala Class 接下来创建一个Scala类:右键单击Scala包>>新建>> Scala类
  6. Name it ScallaHello, select Finish. 将其命名为ScallaHello,选择“完成”。
  7. Paste in the code above and run! 粘贴上面的代码并运行!
  8. If it asks you if you want to configure Classpaths, select Yes. 如果询问您是否要配置类路径,请选择“是”。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM