Version 2, last updated by MattRussell at Dec 15 07:37 2011 UTC
Eclipse Plugin Development using the Scala IDE
These are the steps required if you'd like to use the Scala IDE for Eclipse for your plugin development.
1. Create a normal Java plugin project
I assume you have a normal Java plug-in which you want to extend with Scala code. If you want to create a Scala-only plug-in, you can of course always start with an empty, normal Java plug-in.
2. Configure the project for Scala
You can configure the project automatically or manually:
2a. Automatically add the Scala nature to the project
Right click on the project in the Package Explorer and then select Configure => Add Scala Nature. This will update the .classpath and .project files correctly, and will add scala.library to the required bundles for the plugin.
2b. Manually adapt the .project, .classpath and required bundles
To make the eclipse IDE aware of the Scala code, you have to update the .classpath and the .project files.
If you do it manually, in the .classpath, you have to add the Scala container.To make the running Eclipse plug-in aware of Scala, you have to do one more adaptation. Your manifest file needs to refer to scala.library in its require bundle section:
The .project file should look as follows (Scala builder, Scala nature). Note that the Java builder has been removed, since it is automatically invoked by the Scala builder. At this point, you should be able to mix scala and Java sources. Specifically, you should be able to call scala code from Java code (instantiation, method calls). Note that with versions of the Scala IDE <= 2.7.5.final the Eclipse Java editor might flag references to Scala entities as errors in the left margin of the editor, but not in the Problems view. This is an issue with the JDT integration which will be fixed for 2.8.0. Calling the methods at runtime, however, works. That's it. 3. Deployment Here's a tip regarding deployment from Marcus Wendt: Task: You want to create an Eclipse plugin in Scala or using classes from a Scala library. Problem: Exporting the project using the Eclipse RCP plugin or product dialogues fails because of: "The type scala.ScalaObject? cannot be resolved. It is indirectly referenced from required .class files" More precisely; when Eclipse exports a bundle it seems to create an ant buildfile that calls: <pde.exportPlugins destination="..." exportSource="false" exportType="directory" plugins="..." useJARFormat="true"/> - which is where the compilation process fails. Miles Sabin says: "...for this to work the PDE would have to be aware of the scalac Ant task and include it in that temporary Ant script as appropriate. Unfortunately that's not the case at the moment..." Workaround: Hidden in the plugin export dialog is an option to "use the class files compiled in the workspace" which circumvents this problem and simply packages you bin/* classes into a plugin. The only problem is that this option only exists for plugins not for products - so in the case of a product (e.g. an editor application generated from an EMF model) you have to export the product with failures first and then each scala dependend plugin seperately (using the option mentioned above), replacing the corrupt ones in the product. Previously relevant information that may be of use: ~700 LOC in Scala. HG repo: http://bitbucket.org/mbana/moodmetricsplug-in/overview/. I used Ismael Juma's (http://blog.juma.me.uk/) build of the plug-in, which uses 2.7.3 library, I think the nightly should also work. The plug-in generates the metrics only for Java projects - it won't work for other languages. I guess I could somehow use Scalify so metrics could be generated for Scala projects ... ? BTW. if you've managed to get Scalify working on Linux, please list the steps taken.<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>de.itemis.oo</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>ch.epfl.lamp.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>ch.epfl.lamp.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>
Require-Bundle: all.kinds.of.things,
scala.library
hg clone https://bitbucket.org/mbana/moodmetricsplug-in/