Scala – Deployable Eclipse plugin

Download Example from my GitHub.

To get started

  1. Eclipse >= 3.5 (This tutorial uses 4.3 Kepler)
  2. Eclipse should have plugin development installed
  3. Eclipse should have the Scala IDE installed (this tutorial uses 3.0.2)

1. Create a simple Eclipse Plugin

  1. Open the dialog File->New->Other…
  2. Select Plug-in Project from the list
  3. Enter com.dreadedsoftware.example.eclipse.plugin.scala for the name (Fig 1.1)
  4. Click Next until you reach the “Templates” Wizard Page
  5. Select the “Hello, World Command” option (Fig 1.2)
  6. Click “Finish”

Fig 1.1


Fig 1.2


2. Scalafy your project

  1. Right Click on your project
  2. Configure->Add Scala Nature (Fig 2.1)
  3. Convert to Scala
    1. Right click on the file
    2. Convert to Scala (Fig 2.2)
    3. You’ll see the Convert to Scala Dialog (Fig 2.3)
      1. Select the src folder of your project
      2. Check “Delete Java after Conversion”
      3. “Append original Java as a comment…” is optional
      4. Click OK
    4. You should be left with something like Fig 2.4

Fig 2.1


Fig 2.2


Fig 2.3


Fig 2.4


3. Launch your project

  1. Right click on your project
  2. Run As->Eclipse Application (Fig 3.1)
  3. A new Eclipse instance should begin
  4. In the new Eclipse instance select Sample Menu->Sample Command (Fig 3.2)
  5. A box representing the text in Fig 2.4 will appear…
  6. Or It won’t…

Fig 3.1


Fig 3.2


4. What Happened?

The eclipse plugin builder doesn’t know about scala files even though Eclipse as a whole understands what they are and that they can interact with java files. When the plugin gets packaged into a jar, the build system builds the java files and then just copies the other files in src over into the build. We can have Eclipse illustrate this interaction for us:

  1. Open the META-INF/MANIFEST.MF file
  2. Click the Export button (Fig 4.1 circled in red)
  3. Choose a comfortable destination and click finish
  4. Open the exported jar file in any zip viewer
  5. Inside the zip file navigate to the “com\dreadedsoftware\example\eclipse\plugin\scala\handlers\” folder
  6. Note there is a scala file rather than a class file present (Fig 4.2)

Fig 4.1


Fig 4.2


5. The Solution

  1. Open the META-INF/MANIFEST.MF file
  2. Open the “Runtime” tab
  3. Note the “Classpath” section
  4. Click the “Add…” button (Fig 5.1)
  5. Select the “bin” folder (Fig 5.2)
  6. Click OK
  7. Open the “Build” tab
  8. Note the “Binary Build” section
  9. Make sure “bin” is checked (Fig 5.3)
  10. Launch your project again and the Hello popup should be displayed

Fig 5.1


Fig 5.2


Fig 5.3