Rage Against the Android – Nearly solved! #eclipse #netbeans

After ranting against Android in my previous post I have mainly solved now the untestable situation Android is producing.

Thanks to Robolectric all my tests are finally fast and do not unpredictable hang or similar!

The tests execute nearly as fast as in a normal Maven project – plus additional 2 seconds to bootstrap (dex?). Robolectric was initially made for maven integration on IntelliJ. But it works without Maven and under Eclipse as described here. I didn’t get robolectric working via Maven under Eclipse – and it was overly complex e.g. you’ll need an android maven bridge but when you use a normal Android project and a separate Java projects for the tests then it works surprisingly well for Eclipse.

Things you should keep in mind for Eclipse:

  • Eclipse and Robolectric description here
  • In both projects put local.properties with sdk.dir=/path/to/android-sdk
  • Android dependencies should come last for the test project as well as in the pom.xml for the maven integration (see below)

But now even better: when you are doing your setup via Maven you can use NetBeans! Without any plugin – so even in the latest NetBeans version. But how is the setup done for Maven? Read this! After this you only need to open the project with NetBeans (or IntelliJ).

Things you should keep in mind for Maven and NetBeans:

  • Use Maven >= 3.0.3
  • Again: put the android dependencies last!
  • Specify the sdk path via bashrc, pom.xml or put it into your settings.xml ! Sometimes this was not sufficient in NetBeans – then I used ANDROID_HOME=xy in my actions
  • Make sure “compile on save” is disabled for tests too, as I got sometimes strange exceptions
  • deployment to device can be done to:
    mvn -DskipTests=true clean install      # produce apk in target or use -Dandroid.file=myApp.apk in the next step
    mvn -Dandroid.device=usb android:deploy # use it
    mvn android:run
  • If you don’t have a the Android plugin for NetBeans just use ‘adb logcat | grep something’ for your UI to the logs

Thats it. Back to hacking and Android TDD!

Debugging PHP with NetBeans

How easy is it to make debugging working for PHP code? With NetBeans no problem! Only 5 easy steps!

  1. Download NetBeans 6.9 (although I am using the old 6.8)
  2. If you are on ubuntu installing xdebug is a one liner:
    sudo pecl install xdebug

    write down the path to xdebug for me it is

    /usr/lib/php5/20060613+lfs/xdebug.so
  3. add the following to your php.ini (on my system at /etc/php5/apache2/php.ini):
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    
    zend_extension=/usr/lib/php5/20060613+lfs/xdebug.so
  4. apache2ctl restart.
  5. Set a breakpoint via clicking on the line number. Then right click the project->Debug (Select ‘Server Side PHP’). Now you should see sth. like this:

    Check the ubuntu thread, the xdebug site and the netbeans site if you have still problems.

Now you should be able to execute your code step by step with F8, continue with F5 and e.g view the content of variables: select parts of the code and see the result:

And a lot more feature like inspecting deep objects with the ‘Variables window’:

This is not as mature as the Java Debugger but a better then printing echo statements 😉

Where is UML for NetBeans 6.8?

Flattr this to let me do an update for NetBeans 7.0!

————————————————————————

Recently I wanted the good and fancy UML editor for NetBeans 6.8 to display the class diagram of our twitter search jetwick, but I couldn’t find it in the update center.

The  solution seems is simple. I clicked here and got the zip called netbeans-6.8-200912091457-ml-uml.zip which needs to be extracted into your NetBeans installation. After this I was able to create an UML project from the project menu:

I created a project to reverse-engineer my java project where even maven (jar or war) was possible. Look here:

But at the time of NetBeans 6.5 the packages were filled with content! Now they are empty and no class diagrams can be easily generated from source code 😦

The import of the java files seems to work, because if I right click the project I could create a model report with all my classes and its dependencies.

Do you know my mistake? I just wanted to create a class diagramm from my project.

Update: There seems to be no solution for NetBeans 6.8. See StackOverflow.

Update2: No, wait. Read this.

CRUD with Wicket + Guice + Db4o / NeoDatis

The journey began with a search for a database for my desktop application TimeFinder. It turned out that there are at least 3 candidates if I would choose a simple and only one tier architecture:

  1. GORM
  2. NeoDatis
  3. Db4o

One tier applications would only make sense for some special uses cases like in my case for high schools with one timetable admin. But it would be a lot better if I could use sth. like remote GORM, remote object persistence or even an ajaxified web application. Yes. Why not? What, if I rewrite the UI from scratch and move from ‘Swing Desktop’ to web? But then again: which web framework and which persistent architecture?

A lot of people would recommend Grails (myself included) if I need a simple CRUD web framework, but for me Grails is a bit heavy weight (~ 20 MB) and I will have to live with at least 6 languages: GSP, JS, HTML, ‘Spring-XML’, Java and Groovy. I will need Java at least for the performance critical part: the timetabling algorithm.

Okay. Then, why not GWT or Eclipse RAP? GWT has Javascript compilation, which I am not a big fan of and Eclipse RAP requires pure Eclipse development, I guess. So what else? There are a lot of Java web frameworks (with Ajax) as I discovered earlier. My choice now was simple: Wicket, which is Swing for the web. But what if you don’t like Swing? Then you will love the ‘Swing for the web’ 😉 !

Wicket Features

From what I learned in the last days and from blog posts; Wicket is outstanding in the following areas:

  • Separation of UI and code. You only have
    • pure HTML no new syntax required ala JSP, JSF, GSP, velocity, … the latter one was the reason for not choosing click. No Javascript hassle … if there are some, then I trust the wicket community to fix them in wicket itself
    • and pure Java. This is very good if you’ll someday refactor your code. And you’ll.
  • You can create your own components easy and fast. You can even create ajax components without xml and js… only Java.
  • A strong community (even a German book)
  • No route file necessary. (This can be a disaster for manually managed JSF apps)

Okay. And the persistent layer? That was the reason for this journey … hmmh, there are already several different persistent ‘technics’ for Wicket available:

Hmmh, but I only need a very simple persistent layer. No complex queries etc. As I mentioned earlier I can even live with xml (for datastorage). I decided to look into db4o again (used it in gstpl which is the antecessor of TimeFinder) and into the more commercial friendly (LGPL) object oriented database NeoDatis. The latter one has an option to export to xml and import the same, this would be great so that I don’t have to think about database migrations (some refactorings will be applied automatically. see 1.10 in the PDF docs). Migration in db4o should be easy too.

While I was thinking about that, I asked on the Apache Wicket mailing list for such simple persistent solution. Jeremy Thomerson pointed out that there are even some maven archetypes at jweekend which generates a simple Wicket app with persistence for me. I chose the Wicket+Guice+JPA template and updated this to use Guice 2.0 and the latest warp-persist according to this post. After that I needed to make db4o or NeoDatis working. For the latter one I needed warp-persist-neodatis and for the first one I only needed some minor changes, but they took a bit longer.

Resources

For those who want to see the results, here are the 2 independent maven projects (Apache License 2.0) within my subversion repository (revision 781):

To try the examples just type ‘mvn install’ and run ‘mvn jetty:run’. The resulting war file is amazing small: under 6 MB!

Now point your firefox or opera to http://localhost:8080/timefinderwicket/

And here is the screenshot:

As you can see the localized warning messages are already provided and shown instead of “Please enter a value into the field ‘location'”.

To work with wicket is a great experience! In another project it took me about 10 minutes to convert a normal submit into an ajax one which updates only selected components. And then, in the NeoDatis project I initiallly developed my EventDataView against a completely different data item and moved the source nearly unchanged to the db4o project with the Event class! That is nice component oriented development. Okay, I did copy and paste rather then creating a maven submodule for the pageable list, but that wouldn’t be that difficult with wicket. Then as a third example I overwrote the navigation panel, which was easy too: Now instead of

<< < 1 2 ... > >>

it will be shown

First Prev 1 2 ... Next Last.

without touching the UI. You can even provide ‘properties’ files to apply easy I18n.

Coming Home

Wicket is like coming home ‘to desktop’ after some years of web development, especially in the UI layer. And guice perfectly meets my dependency injection requirements: pure Java.

To get all things right I had to tweek the initial example of jweekend a lot, but all necessary changes were logically and does not smell like a hack. As a first step I updated the versions of the artifacts and then I added a DataView from the repeater examples. The developed CRUD example is now built with dependency injection instead of the original locator pattern (ala DatabaseLocator.getDb()):

@Inject
Provider<ObjectContainer> oc;

Then the update mechanism and some other exception must be solved, but you only need to check out the sources and see what is possible!

As a side note

please keep in mind that there is a NetBeans Plugin for Wicket 1.4.x and an IntelliJ plugin for the same. For all NetBeans guys which are interested in ‘deploy on save’ feature you only need to enable ‘Compile on Save’ and then you can change code or HTML in Wicket, if you are running the application via jetty:run (jetty configuration is already done in the pom). Currently this works only with db4o as a standalone server. To my knowledge this way of UI prototyping can be even faster than with Grails, where it could take some seconds to be recompiled.

Conclusion

Dive into the world of Wicket right now!

Java Application Frameworks (not only client side …)

In an old post I listed all Java libraries,where only two application frameworks were listed.

Today it is time to list some client side Java application frameworks, because I discovered some new ones while reading the W-JAX announcement. Some of the listed frameworks will make developing application with DB easier. And some of them are real 3 tier architectured frameworks. Some of them even allow you to develop RIA’s and web frameworks at the same time.

Here is now the list of open source Java application frameworks especially for the desktop. Feel free to add some more (via comment):

  1. NetBeans RC Platform, my IDE is build on this 😉
  2. Eclipse RC Platform, has an interesting ‘subproject’ called Riena
  3. Spring RC, at the moment my favourite used in TimeFinder
  4. AppFramework which won’t be in JDK 7, but has a lot of derivatives
    1. Swing application framework fork
    2. Guice Utilities & Tools Set
    3. Better Swing AppFramework
    4. with OSGi
  5. JVx, looks very nice! Makes fast development of Swing applications possible (with db support)
  6. OpenXDev a framework which could be used as a base for your next Swing project
  7. Genuine is a client framework for Java Swing applications for which it provides basic infrastructure
  8. Genesis with Swing and SWT binding; Easy, transparent remoting; etc
  9. GWT (although only intented for javascript widgets it could theoretically being used as a rich client running in the jvm)
  10. OpenSwing Framework is an open-source suite of advanced graphics components based on Swing toolkit
  11. Leonardi Framework
  12. Jspresso is a framework for building rich internet applications
  13. Viewa framework
  14. XUI is a Java and XML RIA platform
  15. Swing + XUL = SwiXAT looks interesting but dead, the same for the next:
  16. Swing + XML = SwiXml a small GUI generating engine.
  17. buoy built on top of Swing. Xml serialization of UI possible
  18. But why xml if you have groovy: Griffon 😉
    Now, a nice approach would be to send/receive groovy code and build the clients’ GUI on fly… this would be like replacing the browser+html+javascript system with rock solid JVM+Groovy 😉
    Another Comment from AndresAn addtional tidbit about Griffon, it can be seen as a polyglot programming desktop/RIA framework as it supports 5 JVM languages at the moment: Java, Groovy, Scala, Clojure and JavaFX. It also lets you embed JavaFX components on Swing containers.
  19. JMatter is a software framework for constructing workgroup business applications based on the Naked Objects Architectural Pattern.
  20. Metawidget is a ‘User Interface widget’ that populates itself, at runtime, with UI components to match the properties of your business objects.
  21. Pivot a platform for building rich internet applications in Java

Especially JVx with a webstart demo looks very promising! It even feels better and faster than an ordinary flash application!

Commercial:

  1. Aviantes-Business-Application-Framework
  2. Jide Desktop Application Framework
  3. Jazz

I listed only frameworks which help developers to easier build client side desktop application and only if they run in the JVM. So frameworks where the client is browser-based (aka web frameworks) are not listed here.

For a good list of J2EE frameworks go to java-source.net or to wikipedia. (Or here, or there, or even here)

Update: For additional comments look at dzone