miércoles, febrero 01, 2012

Debugging Griffon in Eclipse/STS

Developing big java clients could sound a little bit strange these days, Where is my Jquery? Where is my Android stuff? :D

All right, I must admit that these days are awful for those in charge of developing Swing apps but there is a great framework out there that could help you a lot.

It's Griffon (http://griffon.codehaus.org/), it's based on Groovy and Grails and it's definitively cool but.... What should I do in order to watch my variables in Eclipse?

Let's get started:
  1. Create an Eclipse project (File > New > Groovy Project; "Create from existing source", i.e. your [projectname] folder, as created by the command line 'griffon create-app')

  2. Preparing everything:

    • You'll need to set GRIFFON_HOME and USER_HOME variables

      • Menu: Window > Preferences

      • Drill into Java > Build Path > 'Classpath Variables', and add a GRIFFON_HOME

      • GRIFFON_HOME as usual

      • Watch out! USER_HOME in Windows could be tricky (ex: C:\Users\ivan.arrizabalaga)

    • Build project (everything should work no error messages)
      • In some cases there is still one error, there is no "services" folder just create it (a workaround, :D).

  3. Start app in 'debug' mode (could be also done from console with griffon run-app -debug):

    • Outside Eclipse create the Ant file for the project (build.xml): griffon integrate-with -ant

    • I'm running the debug-app task from the eclipse 'Ant' view.

      • If you cant see an Ant view, choose menu: Window > Show View > Ant

      • Drag [projectname]/build.xml from the Package Explorer view into the Ant view

      • Expand the project item and double-click debug-app.

      • Then, I'm noting the port number from the console output: [exec] Listening for transport dt_socket at address: 18290

  4. Start a Remote Debugger:
    • Create and save a 'Debug Configuration':

      • Menu: Run > Debug Configurations ...

      • Right-click "Remote Java Application" and select 'New'.

      • In Connection Properties, put Host: localhost, Port: 18290, then click 'Debug'.

    • Change perspective to 'Debug'

Now you can see threads (really important for swing apps), variables (want to see an Alien? inspect an Expando..) but above all Expressions, it will sweeten the experience, :D.

This post is possible due to:
None of them worked for me but if you mix it properly, bumm!