Recent posts (max 20) - Browse or Archive for more

NetBeans Scala Plugin Works on 7.1

>>> Updated on Jan 23, 2011
I just uploaded a new version of Scala plugin for NetBeans 7.1, which fixed the right-click issue. To download:

NetBeans 7.1 released several days ago, I downloaded and installed the plugin for Scala-2.9.x, and it works.

New Web Site for

I just re-launched, which is now based on trac, but on glassfish V3.0 (moved to Jetty 7.0 later) via a custom CGIServlet. It's a headache to get a pretty url for trac, I may re-explore it later.

All old blogs should be imported back here, but not now.

  • Posted: 2009-12-28 18:10 (Updated: 2009-12-29 07:29)
  • Author: dcaoyuan
  • Categories: (none)
  • Comments (61)

Caoyuan's Blog

Caoyuan's blogs about future.

How to Setup Dependencies Aware Maven Project for Scala

I have to say, maintain a couple of dependent projects via Ant is a headache, just like me and others may have encountered when use NetBeans' Scala plugin to create and maintain plain Scala projects, these projects, are all Ant based. It's difficult to write a generic Ant template to compute the dependencies graph and then choose the best building path. The building process of cross dependent projects becomes very slow because the redundant enter/exit dependent projects building task.

NetBeans has also the best Maven plugin integrated, I decided to give Maven a trying. This was actually my first attempt to create Maven based project(s). I explored the mini way toward a Scala Maven project, and patched Scalac a bit again to get the dependencies aware compiling working.

Now here's an example I'd like to share with you.

Assume we have n sub-projects, with cross dependencies, for instance, 'lib.util' and 'lib.math', 'lib.indicators' etc. The simplest Maven way is to keep a parent project (I call it 'modules' here) which holds all common settings and module(sub-project) names(paths). The directory structure could be like:

|-- pom.xml
|-- lib.util
|   |-- pom.xml
|   `-- src
|       |-- main
|       |   `-- scala
|       |       `-- lib
|       |           `-- util
|       |               `-- App.scala
|       `-- test
|           `-- scala
|               `-- lib
|                   `-- util
|                       `-- AppTest.scala
|-- lib.math
    |-- pom.xml
    `-- src
        |-- main
        |   `-- scala
        |       `-- lib
        |           `-- math
        |               `-- App.scala
        `-- test
            `-- scala
                `-- lib
                    `-- math
                        `-- AppTest.scala

What I like Maven here is that the parent project 'modules' only maintains the common settings and module paths, all dependencies between sub-projects are then set in sub-project's self pom.xml file. This is a good decoupled strategy in my eyes, you can freely combine these sub-projects at any time without change too much, and each sub-project doesn't need to care about the dependencies of other projects. The parent project is only a centre place for sharing common setting and a centre place to list all available projects and their directories, it's just like a Directory Service.

Now, here is the pom.xml of parent project looks like (all common settings include compiler, repository etc are kept in it):

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">


    <name>AIOTrade Modules</name>
    <description>Basic Modules for AIOTrade.</description>


            <name>Scala-Tools Release Repository</name>
            <name>Scala-Tools Snapshot Repository</name>

            <name>Scala-Tools Maven2 Repository</name>




And the pom.xml of sub-project 'lib.util' looks like:

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">




The 'lib.math' one:

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">




That's all the settings, clear and clean.

Now, let's back to another level of dependencies: dependencies between Scala source files. How does this setting get scalac aware dependencies of changed sources?

Again, just like the scalac setting in an Ant based project, where at 'configuration' part of build/plugins/plugin/@maven-scala-plugin, I add "-make:transitivenocp -dependencyfile ${}/.scala_dependencies" to 'args' (should be put in separate 'arg' tag as following)


Now the last question, how to use NetBeans to create above setting?

Open "File" | "New Project..." | "Maven" | "Maven Project", click "Next", choose "Maven Quickstart Archetype" to create each empty project, then copy/paste above content to corresponding pom.xml, change project groupId, artifactId and version properties. For existed project, copy your source code to "main/scala". You can also mixed Java code, put then at "main/java", NetBeans Scala plugin supports mixed Scala/Java? project well.

I'll put the pre-defined archetype on net later, so no need to copy/paste, or, you can create an empty parent/sub-project, commit to your version control system. BTW, I find manually modify pom.xml is a pleasure work.

Note No. 1: You have to use/update-to Scala-2.8.0-SNAPHOST with at least scala-compiler-2.8.0-20091128-xxx.jar

Note No. 2: If your project is simple, just use NetBeans created Ant based project. If you separate it to a couple of dependent projects, I strongly suggest you to Maven.

Note No. 3: A new Scala plugin for NetBeans 6.8RC1 will be available before or at Monday, it's also a must upgrade especially for Windows users.

How to Setup Dependencies Aware Ant Project for Scala

During the past days, I was patching scalac ant task and some relative issues, and now, the dependencies aware ant scalac works (post Scala 2.8.0.r19724).

Below is an example build.xml with dependencies aware setting:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project name="ScalaAntTest" default="build" basedir=".">
 3     <description>Builds, tests, and runs the project ScalaAntTest.</description>
 5     <property name="src.dir" value="${basedir}/src"/>
 6     <property name="build.dir" value="${basedir}/build"/>
 7     <property name="build.classes.dir" value="${build.dir}/classes"/>
 9     <target name="init">
10         <property environment="env"/>
11         <condition property="scala.home" value="${env.SCALA_HOME}">
12             <isset property="env.SCALA_HOME"/>
13         </condition>
14         <fail unless="scala.home">set SCALA_HOME first</fail>
16         <property name="scala-library.jar" value="${scala.home}/lib/scala-library.jar"/>
17         <property name="scala-compiler.jar" value="${scala.home}/lib/scala-compiler.jar"/>
19         <path id="build.classpath">
20             <pathelement location="${scala-library.jar}"/>
21             <pathelement location="${scala-compiler.jar}"/>
22             <pathelement location="${build.classes.dir}"/>
23         </path>
24         <taskdef resource="scala/tools/ant/antlib.xml">
25             <classpath>
26                 <pathelement location="${scala-compiler.jar}"/>
27                 <pathelement location="${scala-library.jar}"/>
28             </classpath>
29         </taskdef>
30     </target>
32     <target name="build" depends="init">
33         <mkdir dir="${build.dir}"/>
34         <mkdir dir="${build.classes.dir}"/>
35         <scalac srcdir="${src.dir}"
36                 destdir="${build.classes.dir}"
37                 classpathref="build.classpath"
38                 force="yes"
39                 addparams="-make:transitive -dependencyfile ${build.dir}/.scala_dependencies"
40                 >
41             <src path="${basedir}/src1"/> 
42             <!--include name="compile/**/*.scala"/-->
43             <!--exclude name="forget/**/*.scala"/-->
44         </scalac>
45     </target>
47     <target name="clean" depends="init">
48         <delete dir="${build.dir}"/>
49     </target>
51 </project>

There are some tips here, I'll give a concise explanation:

First, there will be a file call ".scala_dependencies" which is put under "build/" directory after you first clean-build, it will record all dependencies information. Since it's put under "build/", it will be removed automatically after an "ant clean". The "-dependencyfile ${build.dir}/.scala_dependencies" parameter of scalac at line 39 enables this.

Second, you should add "-make:transitive" as scalac's parameter (line 39), which will enable scalac to evaluate the dependencies transitive.

Third, add attribute "force='yes'" (line 38), which tells scalac to check all source files for dependencies and re-compile them if files that dependents on changed.

Forth, you should include "&lt;pathelement location='${build.dir.classes}'/&gt;" as part of "build.classpath" (line 22), so scalac won't complain lack of already generated classes when rebuild upon parts of source files.

I've also re-write the project scheme that created by NetBeans plugin, that is, the next released NetBeans Scala plugin will automatically generate dependencies aware build.xml file for new created projects. Unfortunately, you'll have to copy/move your old project src to new created project directory if you want to benefit from it.

For some reasons, "fsc" is no longer supported as the default compiler task in NetBeans created project, which actually brought some annoyances for plugin users. Even without "fsc", the dependencies aware "scalac" should also work satisfiable in most cases.

  • Posted: 2009-11-19 16:00 (Updated: 2012-01-03 11:04)
  • Author: dcaoyuan
  • Categories: Java
  • Comments (152)

Scala Plugin for NetBeans - Available for NetBeans 6.8beta and Scala 2.8.0 Snapshot

I packed another release of Scala plugin for NetBeans 6.8 beta, for more information, please see:

This version allows adding "deprecation", "unchecked" parameters for scalac, and fixed unicode id issue. It works on Scala-2.8.0 snapshot only.


All projects created via "File" -> "New Project" before this version should add or change following lines in "nbproject/":


Scala Plugin for NetBeans - Available for NetBeans 6.8m2 and Scala 2.8.0 Snapshot

As NetBeans 6.8 m2 released, I packed a downloadable binary which works with Scala 2.8.0.r18993 or above.

Please do not install Scala plugin via Update Center for NetBeans 6.8 m2, it's not compatible. Use the link below to download and install

New & Noteworthy

  • Much more responsive when typing and for code-completion
  • More refactoring: find usages, rename across opened projects
  • Breakpoint works everywhere (almost)
  • Better supporting for mixed Java/Scala project in both direction (Java is visible in Scala and vice versa)
  • Better integration with NetBeans maven plugin
  • Better code completion even for implicit methods (in most cases)
  • Better indentation and formatter for unfinished line after 'if', 'else', '=', 'for', 'while', 'do' etc
  • Better syntax highlighting for val/var, lazy val, implicit call, byname param, abstract method etc
  • Mark of implemented/overridden methods, click on mark will jump to super definition
  • Go to type ("Ctrl+O")
  • Select parts of code, press '{', '[', '(', '"', '`' will add/replace surrounding pair, press '~' will remove them. Specially, press '/' will block-comment it
  • Reset Scala interactive parser when necessary, for instance: dependent libs changed (Right click on source, choose "Reset Scala Parser" in pop-up menu)
  • Output highlighted code to html ([File] -> [Print to HTML...])
  • Some basic hints, for instance: fixing import, unused imports
  • Code template now works, check or add your own via [Options/Preferences] -> [Editor] -> [Code Templates] -> [Scala]

Install with NetBeans 6.8 M2

  1. Download and install the latest Scala-2.8.0 snapshot runtime via Scala's home
  2. Set $SCALA_HOME environment variable to point to the installed Scala runtime path. Add $SCALA_HOME/bin to PATH environment variable. Note for Mac OS user, $SCALA_HOME environment variable may not be visible for Applications/NetBeans, see
  3. Get the NetBeans 6.8 M2 from:
  4. Get the Scala plugins binary from: "
  5. Unzip Scala plugin binary to somewhere
  6. Open NetBeans, go to "Tools" -> "Plugins", click on "Downloaded" tab title, click on "Add Plugins..." button, choose the directory where the Scala plugins are unzipped, select all listed *.nbm files, following the instructions.


  • If you encounter "... Could not connect to compilation daemon.", try to run "fsc -reset" under a command/terminal window.
  • Editor $NetBeansInstallationPath/etc/netbeans.conf, remove "-ea" to avoid AssertionError popped up for more information

Notice for Host Migration of This Site

I'm going to migrate this web site to new host during this month, both and may not be available at any time during this period.

Scala Plugin for NetBeans - Rewrite in Scala #8: Partly Visible to Java and Go to Type

>>> Updated on Sep 8:
Now in most cases, Scala is visible to Java, including generic type. Mixed Java/Scala? project should be well supported.

I need "Go To Type" working, and Scala's symbols should be visible to Java sources. For NetBeans, that means I should implement a Scala to Java VirtualSourceProvider?, which will translate Scala source to Java stub.

I tried it before, but not so successful, so I disabled it. Finally, I got how it works today, and committed work in part. That is, now, in Scala/Java? mixed project, not only Java is visible to Scala source, and also, partly, Scala is visible to Java too.

Another benefit is, when you press "Ctrl + O" or "Command + O", a navigator window will bring you to Type's source file that you are searching.

I'll go on to get Scala -> Java mapping fully works soon.

>>> Updated on Sep 8:
The following issue was fixed in trunk.

Warning: If you have not got a NetBeans nightly built before, do not try it until a recent (after Sep 3rd) serious fault fixed.

Scala Plugin for NetBeans - Rewrite in Scala #7: Mark Override Method and Go to Super def

The new progress is a little mark at the left side bar of editor, showing if a method is overriding a method of base class/trait. Move cursor on this mark will show a tooltip, and, click on this mark will jump to source of super definition.

If a mark of (D) shown and you forget to add "override", you will wait until a whole build process to tell you lacking of "override", so pay attention to it.

Of course, if it's an (I) mark, you do not need to add "override".

Scala Plugin for NetBeans - Rewrite in Scala #5: Refactoring Step One - Finding usages

I'm working on Refactoring features for NetBeans' Scala plugin, the first step is finding usages of class/method/val etc across project's source files, it works now. The next step will be renaming them.

Following snapshot shows class "ScalaDfn?" are used in 19 places, across 6 Scala sources

Scala Plugin for NetBeans - Rewrite in Scala #6: Refactoring Step Two - Rename

As I've done most code of Refactoring skeleton, it did not cost me too much time to get renaming feature working (2 hours about). Now, NetBeans' Scala plugin can rename class/method/val etc across project's source files.

Following snapshot shows class "Dog" is going to be renamed to "BigDog?". After the preview, press "Do Refactoring", all things done.

Scala Plugin for NetBeans - Rewrite in Scala #4: How to Use It to Develop Scala Itself

I begin to patch Scala's new designed compiler interface for IDE to get it work better (with NetBeans, and, other IDEs). I know lamp term may use Eclipse as their IDE to develop Scala itself, but I'm using new written NetBeans plugin. Here's a short tutorial of how to use NetBeans Scala plugin to work with Scala itself

Build Scala-2.8.0 snapshot

First and least, svn check out Scala's trunk source code:

cd ~/myprjs/scala/scala
svn co

Then, make sure your $JAVA_HOME is pointed to a JDK 1.5 instead of 1.6, and clear $SCALA_HOME. "ant dist" to build a fresh Scala distribution, which is located at ~myprjs/scala/scala/dist/latest

# As for Mac OS X
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
export SCALA_HOME=
ant dist
export SCALA_HOME=~myprjs/scala/scala/dist/latest

Install latest NetBeans and Scala plugin

Download latest NetBeans nightly built from, the minimal pack "Java SE" is enough.

Run NetBeans, get latest Scala plugin via: [Preference/Option?] -> [Plugins] -> [Available Plugins], find "Scala Kit" in the list and choose it,following the instructions to get it installed, restart NetBeans.

Create NetBeans project by importing existing sources

Create project for Scala's trunk sources. Note: each folder under "src" should be considered as standalone folder, for example, "compiler", it's better to create standalone project for each these folder, I created two, one for "compiler",another for "library".

[File] -> [New Project] -> [Scala] -> [Scala Project with Existing Sources]

Click [Next], input project name that you like Note: you can input an existed ant build script file name in "Build Script Name". Or, modify the auto-created one later, it's a plain ant build xml file. Click [Next], add source folder:

Click [Next] again, you can see the sources that will be included in this project, then click [Finish]

Now, Scala's compiler has been imported as a NetBeans freeform project, it is an old plain ant project. You can create another one for Scala's library.

How to debug into Scala's compiler, library source?

If you have a project that want to debug into Scala's compiler, library sources, you could do when in debugging:

In debugging, open debugging source windows via: [Windows] -> [Debugging] -> [Sources]. Go through the listed source jars, find ".../scala-compiler.jar" and ".../scala-library.jar", check them.

Scala Plugin for NetBeans - Rewrite in Scala #3: Ready for Beta Test

I struggled with new redesigned IDE / compiler interface (interative.Global) during this weekend, and finally, got it attached to NetBeans Scala plugin, which runs as a background daemon thread, thus the plugin is more responsive when coding (the first benefit). It was a hard work though, I had to modify some of the original code to get whole things stable and responsive (balance), it paid me 2 sleepless nights.

So here's what's new on current nightly built:

  • Tested and work with Scala 2.8.0.r18542 snapshot
  • Better supporting for mixed Java/Scala? project
  • Better indentation and formatter for unfinished line after 'if', 'else', '=', 'for', 'while', 'do' etc
  • Better code completion even for implicit methods (some times)
  • Implicit method call will be highlighted by underline
  • Select parts of code, press '{', '[', '(', '"', '`' etc will add/replace surrounding pair, press '~' will remove them. Specially, press '/' will block comment it
  • Some basic hints, for example, fix import (from Milos' work)
  • Code template now works, check or add your own via [Options/Preferences?] -> [Editor] -> [Code Templates] -> [Scala] (from Milos' work)

Note: wait until Monday night for NetBeans' hudson builds those whole new nbms.

I think this plugin is qualifiable for beta using/testing now. If you are interested in testing/reporting bugs, you can get the latest NetBeans nightly built, and got the new Scala plugin from Update Center, download a Scala-2.8.0 snapshot, live your $SCALA_HOME to this Scala 2.8.0 snapshot, change $PATH to including $SCALA_HOME/bin.

By testing/using Scala 2.8.0 right now, we can also push it improved more quickly.

BTW, I'm using this plugin on whole Scala' trunk source and of course, this plugin.

Scala Plugin for NetBeans - Rewrite in Scala #2: Supports Java/Scala Mixed Project

Java/Scala? mixed project was supported partly once before, but I cannot remember when this feature got lost. Anyway, as one progressing of the rewritten NetBeans Scala plugin, I just got this feature working properly halfway: now Java source is visible to Scala one, but not vice versa. To got Scala source also visible for Java source, would pay for efficiency, since the compiler may need to be pushed to a deep phase, and mapped to Java classes/methods, I need more time to think about that.

Below is a screenshot that a JavaDog? is called from a Scala source file:

Scala Plugin for NetBeans - Rewrite in Scala #1: Almost Done

The previous Scala plugin for NetBeans was a rush work which was written in Java, toward a useful tool to support writing Scala code. I called it chicken, which was then can be used to produce new Scala plugin written <b>in Scala</b>, that was, the egg.

The egg has grown to a chicken now. As for last night, I switched whole scala modules to depend on the new written scala.editor module (in Scala), and use this new chicken to improve Scala plugin from now on.

The new scala plugin will be carefully rewritten, with a lot of APIs supporting for language editor in mind, and try to support better and more features toward a whole featured, stable Scala IDE.

Another good news is, Milos Kleint, the contributor to NetBeans Maven plugin, has also put hands on this project, he's working on better Scala support for maven project, and new templates/hinds features for Scala editor modules.

The new plugin is based on Scala 2.8 snapshot, if want to get it, you should use the nightly built NetBeans from, and get the new plugins via updated center.

Note: you have to install the latest Scala 2.8 snapshot too, and make sure $SCALA_HOME, $PATH pointed to it. For maven project, you should also update your pom.xml to depend on Scala -2.8-snapshot.

Below is a working snapshot that I was using new Scala plugin to write Scala plugin:

Scala Plugin for NetBeans: Scala 2.8 Snapshot

Don't forget to download a fresh Scala 2.8.0-snapshot from (you may want to track the progress of 2.8.0 once a week etc), and set SCALA_HOME, PATH environment to point to the installation of it.

=== During the weekend, I built a fresh Scala 2.8.0 snapshot. With ticket #2163 fixed in 18 hours (great job, Scala team), I got a Scala plugin for NetBeans that works under Scala 2.8.0. I then re-built whole Erlang plugin (which is written in Scala), by fixing some minor incompatible issues, it works too.

So, at least, Scala 2.8 seems stable enough for writing a NetBeans plugin now.

Here's a snapshot showing some new features of 2.8.0

If you are eager to have some taste of Scala 2.8.0 with NetBeans plugin, and is patient to keep another NetBeans nightly version on your machine, then, wait for one more day from now for NetBeans hudson to build whole things, download the lasted NetBeans nightly version, and install "Scala Kit" module via "Update Center".

Don't forget to download a fresh Scala 2.8.0-snapshot (you may want to track the progress of 2.8.0) from, and maintain your SCALA_HOME, and PATH environment for different Scala versions

BTW, if I have time, I'll begin to rewrite this plugin in Scala, on 2.8.0

Rats! Plugin for NetBeans#1: Syntax Highlighting

I've used Rats! parser generator heavily on Scala/Erlang? plugin for NetBeans, but not write a plugin for Rats! itself.

So I spent my weekend days on a simple Rats! editor module, which implemented syntax highlighting. It's built on Scala.

Here's the snapshot:

It will be available in couple of days.

Erlang Plugin Version 1 for NetBeans 6.7 Released

I'm pleased to announce Erlang plugin (ErlyBird?) version 1 for NetBeans 6.7 is released.

NetBeans 6.7 RC3 or above is a requirement.

What's new:

  • It's rewritten in Scala instead of Java
  • More reliable instant rename
  • Display extracted document information from source comment when doing auto-completion.

To download, please go to:

To install:

  • Open NetBeans, go to "Tools" -> "Plugins", click on "Downloaded" tab title, click on "Add Plugins..." button, choose the directory where the Erlang plugin are unzipped, select all listed *.nbm files, following the instructions.
  • Make sure your Erlang bin path is under OS environment PATH, you can also check/set your OTP path: From [Tools]->[Erlang Platform], fill in the full path of your 'erl.exe' or 'erl' file in "Interpreter", for instance: "C:/erl/bin/erl.exe". Or open the "Brows" dialog to locate the erlang installation.
  • When you open/create an Erlang project first time, the OTP libs will be indexed. Take a coffee and wait, the indexing time varies from 10 to 30 minutes depending on your computer.

Feedback and bug reports are welcome.

Scala Plugin Version 1 for NetBeans 6.7 Released

>>> Updated on July 1, 2009
There are couple of reports on "Could not connect to compilation daemon.", mostly under Windows OS. It's a known issue, to resolve it, please check the following:

  1. SCALA_HOME is set to a fresh installed Scala runtime
  2. PATH includes $SCALA_HOME/bin
  3. If the build task still complain, try to run "fsc" or "scala" in a command window first


I'm pleased to announce the availability of Scala plugin version 1 for NetBeans 6.7

What's new:

  • Use fsc instead of scalac as the project building compiler (If you've set SCALA_HOME, make sure $SCALA_HOME/bin is included in your PATH environment).
  • Fixed setting breakpoint in closure statement.
  • A basic import-fixer (Right click on source, then choose "Fix Imports").
  • Code assistant for local vars and functions.
  • Run/Debug? single file.

To download, please go to:

For more information, please see

Bug reports are welcome.

It works on NetBeans 6.7 RC1 or above.