0

After about 6-7 hours in a row, I'm hoping that somebody can help me with a problem I am having. Basically I'm trying to develop a Eclipse plugin containing both Scala and Java code. Unfortunately it is such that when I'm trying to build the plugin, I get errors of this kind:


File: @dot.log 04-04-12 19:02:49 CEST Eclipse Compiler for Java(TM) 0.A76_R36x, 3.6.2, Copyright IBM Corp 2000, 2010. All rights reserved.

  1. ERROR in C:\Documents and Settings\b96274\workspace_scala_akka\TestScala\src\testscala\Activator.java (at line 16) ScalaTest t = null; ^^^^^^^^^ ScalaTest cannot be resolved to a type

1 problem (1 error)

The two classes I have defined are:

"Activator.java"

package testscala;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

private static BundleContext context;

static BundleContext getContext() {
    return context;
}

public void start(BundleContext bundleContext) throws Exception {
    Activator.context = bundleContext;
    ScalaTest t = null;
}

public void stop(BundleContext bundleContext) throws Exception {
    Activator.context = null;
}
}

"ScalaTest.scala" package testscala

class ScalaTest {
  val t = "whatever"
}

I create the plugin as first a Plugin Project, and the afterwards add Scala nature to it. To inform the PDE builder of scala I have used: http://www.michel-kraemer.com/scala-projects-with-eclipse-pde-build-2 Michel Kraemers very excellent build file.

My build.properties file is:

source.. = src/

output.. = bin/

bin.includes = META-INF/,\

.

customBuildCallbacks=customBuildCallbacks.xml

customBuildCallbacks.inheritall=true

and the customBuildCallbacks.xml is stored in the buttom of the project.

I have tried with nightly and the stable build branch of the Scala IDE plugin. Also fresh versions of Eclipse 3.6.2 and 3.7.2 have been tried. I have gotten plugins working before with this setup, unfortunately I seems to have been forgetting some (basic?) stuff.

I can use the workaround "Use class files compiled in workspace", but I need the PDE builder to work with this. Can anyone please help, I will of course give more details if needed.

My guess is that the Java compiler can't see compiled Scala files since they first will be compiled later, but that's only an guess.

Thanks in advance. Regards Stefan Ettrup

StefanE
  • 817
  • 6
  • 20
  • It should work. What builders do you have under 'Project Properties/Builders'? I have the following: * Scala Builder * Plug-in Manifest Builder * Extension Point Schema builder – Iulian Dragos Apr 06 '12 at 18:42
  • Hi Iulian. I have the same 3 builders in the same order as you mention it. Are you able to create a plugin sample project, where this does work when using the export feature? – StefanE Apr 06 '12 at 20:11

2 Answers2

0

I am also using this approach. Basically, I believe it doesn't support Java code depending on Scala code, because the Java compiler has to run first and it it fails, Scala compiler isn't even tried. At least that was my experience. Of course, Java code can depend on Scala code in other plugins, because it only ever sees bytecode from there.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • DO you know if it's possible to run the Scala compiler before the Java compiler? Matthev says it's possible for the Scala compiler to understand Java source. Then I guess it would be okay to compile Scala before Java? – StefanE Apr 08 '12 at 14:26
  • @StefanE You could do it in the `pre.@dot` target. But I don't know PDE Build well enough to tell whether it's possible to tell the Java compiler about compiled .class files. – Alexey Romanov Apr 09 '12 at 09:58
0

The java compiler does not understand scala files, but the scala compiler does parse/understand java files. The scala compiler does not, however, compile java files, it only compiles scala files. So, to compile a combined java/scala plugin, you generally have to:

1) Compile your scala, including your java source tree. This generates the .class files for your scala files. 2) Compile your java, including the .class files generated above. This generates the .class files for your java files. Anything java which depends upon the scala classes should be compiled correctly.

So do the scala compilation first. Sometimes, you'll need to add a third step, to compile your scala again, using the class files generated by the java compiler. But this is rare.

I'm afraid I don't know how to do this with ant, but I'm sure it's possible.

For scala-ide, this is even easier, because there is an option in Window->Preferences->Scala->Compiler tab Build manager, you can choose compileorder (Mixed, JavaThenScala, ScalaThenJava). Try this as well.

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
  • The problem with your last paragraph is that "Export plugins" and "Export product" does _not_ use Scala IDE's builder. So it works perfectly well when run from IDE, but exporting fails. – Alexey Romanov Apr 06 '12 at 21:38