在 Eclipse 项目中混合 Scala 和 Java 文件

发布于 2024-10-07 21:20:52 字数 446 浏览 3 评论 0原文

我可能在做一些愚蠢的事情,但我无法发现它。

我已经安装了 Eclipse Helios(Helios 因为我无法使用 Gallileo 获得 Glassfish 支持来正常工作)以及 Helios 的 Scala Eclipse 插件的夜间构建

我创建了一个 Scala 项目并添加了一些文件 - Java 和斯卡拉。

它们在语法上似乎都是正确的 - Eclipse 编辑器至少似乎知道每个文件是什么语言,并且在我创建它们时正确报告语法错误 - 但 Java 文件找不到在 Scala 中创建的类。 IDE 站点似乎表明这应该可以正常工作。

bin 目录中没有任何 Scala 文件的类文件(Java 文件定义的每个类都有类文件),因此似乎由于某种原因未构建 Scala 文件。这些丢失的类文件可以解释为什么 Java 文件看不到这些类。

我错过了什么?我如何告诉 Eclipse 构建这些文件?

I'm probably doing something stupid, but I can't spot it.

I've installed Eclipse Helios (Helios because I couldn't get Glassfish support to work correctly using Gallileo) and the nightly build of the Scala Eclipse plugin for Helios

I've created a Scala project and added some files - a mix of Java and Scala.

They all seem syntactically correct - the Eclipse editor at least seems to know what language each file is, and reports correctly on syntax errors when I make them - but the Java files cannot find classes created in Scala. The IDE site seems to suggest this should all just work.

There are no class files in the bin directory for any of the Scala files (there are class files for each of the classes defined by the Java files) so it seems that for some reason the Scala files aren't being built. These missing class files would explain why the Java files don't see the classes.

What have I missed? How do I tell Eclipse to build those files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你曾走过我的故事 2024-10-14 21:20:52

我也在使用 Helios(因为我已经使用了 64 位),并且发现该插件有时表现得有点奇怪(尽管说实话,与 Galileo 中的插件没有太大不同)。当混合 Java 和 Scala 时,正如您所发现的,看起来没有问题,但不会有编译后的代码。或者更糟糕的是,依赖于 Scala 类的 Java 类无法编译,因为 Scala 类未编译 - 但直到项目中的所有错误都消失后,它才会编译,当然,在编译之前不会发生这种情况... 呃。

我开始修改类路径和项目文件,并最终让它工作,尽管我不能真正说出原因。我发誓我更改了一个文件,然后又改回来,然后它就起作用了?

无论如何,这是我的文件:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>xxxxxxxxxxxxx</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
    <buildCommand>
        <name>org.scala-ide.sdt.core.scalabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
</buildSpec>
<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
    <nature>org.scala-ide.sdt.core.scalanature</nature>
</natures>
</projectDescription>

并且

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>

关键的事情似乎是 SCALA_CONTAINER 出现在 JRE_CONTAINER 之前,但是......我也不会打赌。 “性质”的顺序也可能很重要。

它已经为我工作了一两周了,每天更新,所以...... *祈祷*

I'm also using Helios (because I've gone 64-bit) and found the plugin behaving a bit odd at times (though to be honest not much differently than in Galileo). When mixing Java and Scala, as you found, it would look like there's no problem, but there would be no compiled code. Or worse a Java class dependent on a Scala class wouldn't compile because the Scala class wasn't compiled -- but it wouldn't compile until all the errors were gone from the project, which of course wouldn't happen until it compiles... ug.

I began tinkering with the classpath and project files, and eventually got it to work, though I can't really say why. I swear I changed a file, then changed it back, and then it worked??

Anyway, here are my files:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>xxxxxxxxxxxxx</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
    <buildCommand>
        <name>org.scala-ide.sdt.core.scalabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
</buildSpec>
<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
    <nature>org.scala-ide.sdt.core.scalanature</nature>
</natures>
</projectDescription>

and

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>

The critical thing seems to be that SCALA_CONTAINER come before JRE_CONTAINER, but... I wouldn't bet on it either. The order of the "natures" may be important, too.

It's been working for me now for a week or two, with daily updates, so... *fingers-crossed*

半岛未凉 2024-10-14 21:20:52

我注意到,当我创建新文件时,Eclipse-IDE 有时不会编译我的 Scala 文件。我必须在 Package Explorer 中选择该项目并刷新它 (F5)。另外,您可以通过以下方式更改 Eclipse 中的编译顺序(Java 优先与 Scala 优先):

Window->Preferences->Scala->Compiler->Build Manager->compileorder

I've noticed that Eclipse-IDE sometimes doesn't compile my Scala files when I create a new file. I have to select the project in Package Explorer and refresh it (F5). Also, you can change the compilation order (Java first vs. Scala first) in Eclipse by going to:

Window->Preferences->Scala->Compiler->Build Manager->compileorder

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文