Mixing Scala and Java files in an Eclipse project(在 Eclipse 项目中混合 Scala 和 Java 文件)
问题描述
我可能在做一些愚蠢的事情,但我无法发现它.
I'm probably doing something stupid, but I can't spot it.
我已经安装了 Eclipse Helios(Helios,因为我无法使用 Gallileo 获得 Glassfish 支持以正常工作)和用于 Helios 的 Scala Eclipse 插件的夜间构建
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
我创建了一个 Scala 项目并添加了一些文件 - Java 和 Scala 的混合体.
I've created a Scala project and added some files - a mix of Java and Scala.
它们在语法上似乎都是正确的——Eclipse 编辑器至少似乎知道每个文件是什么语言,并且在我制作它们时会正确报告语法错误——但是 Java 文件找不到在 Scala 中创建的类.IDE 站点似乎建议这一切都应该正常工作.
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.
bin 目录中没有任何 Scala 文件的类文件(Java 文件定义的每个类都有类文件),因此似乎由于某种原因没有构建 Scala 文件.这些丢失的类文件可以解释为什么 Java 文件看不到这些类.
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.
我错过了什么?我如何告诉 Eclipse 构建这些文件?
What have I missed? How do I tell Eclipse to build those files?
推荐答案
我也在使用 Helios(因为我已经 64 位),发现插件有时表现得有点奇怪(虽然老实说不多不同于伽利略).正如您所发现的,当混合 Java 和 Scala 时,看起来没有问题,但不会有编译代码.或者更糟糕的是,依赖于 Scala 类的 Java 类不会编译,因为 Scala 类没有被编译——但它不会编译,直到所有错误都从项目中消失,这当然不会发生,直到它编译...呃.
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>
和
<?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 之前,但是......我也不会打赌.自然"的顺序可能也很重要.
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*
这篇关于在 Eclipse 项目中混合 Scala 和 Java 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Eclipse 项目中混合 Scala 和 Java 文件
基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01