Sha*_*ane 10 java eclipse scala jar jruby
我能够让所有三个人在"Scala项目"中运行一个Hello World,并以.java文件为主.问题是它是从我没有使用的"Java项目"中提取的,尽管我的"Scala项目"中有JRE系统库.以下是我正在做的有助于理解的代码......
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!");
}
}
Run Code Online (Sandbox Code Playgroud)
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!")
}
Run Code Online (Sandbox Code Playgroud)
最终结果是......
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!
Run Code Online (Sandbox Code Playgroud)
我把这些罐子组织成了Scala Library,JRE Library和JRuby Jar的Referenced Libraries.我也不想使用"Java项目"中的相同内容.如果我关闭该项目,则此项目"Scala项目"无法运行.显然这不是一个重要的项目,但我想更好地理解这是如何工作的.
我最终在第一周内就解决了这个问题。这就涉及到一个依赖问题。我建立了一个新项目并且成功了。这个问题有一段时间不活跃,直到 om-nom-nom 提供+50 的答案。如果有人觉得仍然需要答案,我很抱歉。为了让这个答案对其他人来说是足智多谋的,我在http://shaneofalltrades.com/java.html上开设了一个博客,其中包含有关完整设置的详细信息。这是该教程的副本...
\n\n如果您已经有 Eclipse,则应该能够使用该版本,或者按照以下步骤安装另一个 Eclipse 以保持此环境独立。
\n\n现在我们要暂时离开 Scala 并下载 JRuby。如果您不需要 Ruby,则可以跳过此步骤,或者您可以使用此步骤将 JRuby 添加到 Java 项目。
\n\n这应该涵盖了 Java、Scala 和 Ruby 的 Hello World 的所有内容。如果您有任何问题,请询问,我很乐意为您提供帮助。
\n