19
votes

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?

2
Just in case, check for builders in the project properties windows and make sure Scala is checked. - pedrofurla
Another wild guess, use different source folders. One for Scala and one for Java, never had any problems doing like that. - pedrofurla
Thanks. Checked that Scala builder was selected and moved the Java files to a different folder. Didn't help :( - The Archetypal Paul
If you remove all the .java files (or all the .scala files) does it work? - Rodney Gitzel
I stumble at this thread from google search. From what I have found. It seems like the problem doesn't come from scala part. Here is what I did. 1.build project, 2. make java and scala files 3. add scala nature. 4. try to build it (with java file import some class from scala file). This gave me error, so I tried to remove all scala nature/class and modify java file to a vanilla helloworld program. it still gave me same error (no class found or sort of). - Tg.

2 Answers

9
votes

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*

8
votes

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