在Eclipse项目中混合Scala和Java文件 [英] Mixing Scala and Java files in an Eclipse project

查看:667
本文介绍了在Eclipse项目中混合Scala和Java文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我已经安装了Eclipse Helios(Helios,因为我无法获得Glassfish的支持使用Gallileo正常工作)和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.

在任何Scala文件的bin目录中没有类文件(每个都有类文件由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类没有被编译 - 但是直到所有的错误都从项目中删除之后才会编译,当然这不会发生,直到它编译... ug。

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.

现在一直在为我工作一两个星期,每天更新,所以... *手指-crossed *

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

这篇关于在Eclipse项目中混合Scala和Java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆