Wednesday Jul 30, 2008

Run/Debug Lift Web App Using Scala/Maven Plugin for NetBeans

I'm a newbie to Maven, so I encountered some issues when run/debug Lift apps. The following are tips that I got, it may not be perfect, but at least work.

1. When pom.xml is changed, and classes not found errors happen on editor, you can close and reopen the project

This is a known issue, that I didn't refresh compiling context when pom.xml changed, thus the classpath dependency may be not refreshed at once, I'll fix this issue in the near future.

2. Run project by external Maven instead of embedded Maven of NetBeans plugin

I encountered "java.lang.NoClassDefFoundError org/codehaus/plexus/util/DirectoryScanner" when use embedded NetBeans Maven plugin (3.1.3) when invoke "Run" project, but fortunately, you can custom the binding actions in NetBeans Maven. The steps are:
  1. Right click project node, choose "Properties"
  2. Click on "Actions" in left-pane, choose "Use external Maven for build execution", and "set external Maven home"
  3. Choose "Run project" in right-pane, input "jetty:run"
  4. Choose "Debug project" in right-pane, input "jetty:run"

3. How to debug project

I'm a bit stupid here, since I don't like to change MAVEN_OPTS frequently. So I choose to do:

$ cd $MAVEN_HOME$/bin
$ cp mvn mvn.run
$ cp mvnDebug mvn

Then I invoke "Debug" action from NetBeans toolbar, and get NetBeans' output window saying:

WARNING: You are running Maven builds externally, some UI functionality will not be available.
Executing:/Users/dcaoyuan/apps/apache-maven-2.0.9/bin/mvn jetty:run
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000

Open menu "Debug" -> "Attach Debugger...", in the popped window, for "Port:", input "8000". Everything goes smoothly then. You add/remove breakpoints just as you are doing for a regular Scala project.

Of course, if you want to turn back to "Run" from "Debug", you have to "cp mvn.run mvn" back.

Anybody can give me hints on how to get this setting simple? in NetBeans Maven plugin.

Here's a snapshot: (click to enlarge it)

nn

Comments:

About point 2.

I also suggest to change the global configurationof the maven plugin to use an external maven (Tools/Options/Misc/Maven).
Then less memory will be used by netbeans and memory used to build will be freed after build (fork an external process).

About point 3.

need some try to find a better solution.

Posted by DavidB on July 30, 2008 at 03:50 AM PDT #

point 2.
I suggest you file an issue against the scala plugin or maven core (not sure what's the problem but it has to do with running 2.1-SNAPSHOT maven in embedded mode.

point 3.
I would say you shall be passing the debugger parameters to the jetty:run goal. That's done in the Project properties' Actions panel. You would set there that debug project action is mapped to jetty:run with the special property setup that will make sur ethe jetty's JVM is debuggable. Then attach to it from the IDE. I think the attaching could be done by the IDE support automatically as well, but I would have to try myself.
Please note that if jetty server is running in the same VM as the maven build and the maven build is embedded, you won't be able to debug such app. (cannot attach VM to itself)

Posted by Milos Kleint on July 30, 2008 at 11:04 PM PDT #

Post a Comment:
Comments are closed for this entry.