gpt4 book ai didi

java - 如何在 Eclipse 中打开 Java、Scala 和 JRuby 的单个项目?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:58:45 25 4
gpt4 key购买 nike

我能够让所有三个在“Scala 项目”中以 .java 文件作为我的主要文件运行 Hello World。问题是它是从我没有使用的“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!");
}
}

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!")
}

最终结果是...

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!

我将 jar 组织为 Scala 库、JRE 库和 JRuby Jar 的引用库。我在不想使用的“Java项目”中也有同样的东西。如果我关闭该项目,则该项目“Scala 项目”将无法运行。显然这不是一个重要的项目,但我想更好地了解它是如何工作的。

最佳答案

在 Scala 项目中使用 Java 代码应该没有问题。您一定是无意中声明了从 scala 项目到 Java 项目的依赖关系,但没有更多信息,我无法判断。

请附上您的 scala 项目的 .classpath 和 .project 文件。

关于java - 如何在 Eclipse 中打开 Java、Scala 和 JRuby 的单个项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8964506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com