views:

1284

answers:

7

The Scala Eclipse plugin page says: * Support for Eclipse plugin and OSGi development including hyperlinking to Scala source from plugin.xml and manifest files.

How does this support work? There's no wizards for making Scala plugins. I've found no documentation on how to use Scala in a Eclipse plugin/RCP application. Is it even possible?

+2  A: 

Yes, it is possible. In fact, the Scala Eclipse plugin itself is written in Scala.

I've never created a Scala RCP app myself, but I'm guessing that what you need to do is create the project normally using your wizard of choice. Once the project is in your workspace, right-click and select "Add Scala Nature" (or something to that effect). The result will be a Scala project with all of the regular trappings of an RCP app. You should be able to use both Java and Scala within the project after these setup steps.

Daniel Spiewak
Yes, I tried that but for some reason the scala code was never executed. It didn't crash or anything just didn't run the scala part.
Olli Aalto
+1  A: 

After adding Scala Nature to the plug-in project, don't forget to include scala.library among the dependencies of your plugin (and update the corresponding run and product configuration)! (Additionally, if another JRE system library appears in the build path when adding Scala Nature, you can safely remove it to avoid the RequiredExecutionEnvironment warning.)

thSoft
Just to update: with more recent versions of the plugin, it should automatically add the Scala library dependency when you add the Scala nature to a plugin project.
Matt R
+1  A: 

Did anyone get it to work as an actual exported product? I was happily developing my scala plugin and it was running great inside Eclipse, but when I tried to export the product, the build process failed saying it couldn't resolve my scala object to a type. I found this bug report:

http://lampsvn.epfl.ch/trac/scala/ticket/1919

+2  A: 

The reason the plugin code written in Scala doesn't work with RCP is simply that the .class files don't get exported when the plugin jar is built. But there is a workaround you can use: Open the plugin.xml with the Plug-In Manifest Editor, select the Runtime tab and add a new entry "bin" for the classpath. Then on the Build tab, in the Binary Build tree, select the bin folder. The class files that are compiled in the workspace are then exported into the plug-in jar when you export the product.

Andreas Textor
+1  A: 

The Scala Nature invokes the JDT compiler and makes the Java classes available tot he Scala compiler. I was having an issue where I have both the Scala Nature and Java Nature enabled. Make sure you don't have the Java Nature enabled.

arcticpenguin
+2  A: 

This is an old question; but an update may be helpful to someone.

I can say that I have successfully created a Scala RCP application using the scala 2.8.0 beta release. The improvements are notable. I followed the steps described here. It was easier than I initially thought.

For good measure I then translated the Java code to Scala ... one file at a time.

Willem
A: 

This tutorial should be of help:

http://www.coconut-palm-software.com/the_new_visual_editor/doku.php?id=blog:using_scala_to_create_eclipse_rcp_applications

I tried it out and it worked for me.

hedefalk