Sunday, December 30, 2012

Scala JavaFX Archetype

The scala-javafx-archetype helps you set up an environment for coding JavaFX with Scala.

Waiting at The Stairs
Waiting at The Stairs von aalfath bei Flickr
Last week I've published an archetype for maven to generate a simple maven project using Scala and JavaFX on GitHub.

In my opinion it is most important to have such gadgets to ease the burden of setting up an environment to start coding. I know from myself that you'll quickly lose interest in exploring a technology (at least in your sparetime ;-) ) if you have to solve a plethora of things before you actually come to the point which interests you.

There are also other archetypes which do roughly the same, like the one of Schlichtherle IT Services. In its latest version it uses still Scala 2.8.2 and JDK 1.6, which is not what I wanted. Looking at the generated pom, it uses also Scalacheck which I didn't need and old versions of the scala-maven-plugin.

Besides in the meantime, Daniel Zwolenski released a great maven plugin for building JavaFX applications which I wanted to support.

Thirdly, I just wanted to know how to get a maven artifact to the central repository. Being (among other things) a 10y+ Java developer, it just amazes me how some projects bootstrap themselves just by calling mvn package at the right time and the right place.


Thus my decision to implement this Hello World archetype, which, by the way, took less time than to write this blog post.

In hindsight, to my surprise, the process of getting into maven central was not really that hard, although you have to know quite some stuff and should have at least a glimpse of an idea what all related technologies are good for.

Alors ...

What is a maven archetype?

In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made. The names fits as we are trying to provide a system that provides a consistent means of generating Maven projects. Archetype will help authors create Maven project templates for users, and provides users with the means to generate parameterized versions of those project templates.
For a thorough explanation see the introduction documentation on the original apache site. 

Just a little warning: The documentation on maven is fragmented, there are bits and pieces written from different authors for different versions of the maven product itself. As such, in my opinion, it is sometimes confusing and harder than it should be to follow the main point. 

On the other hand it is a hard problem to provide good documentation, maybe you can contribute

How to create an archetype?


You can do it the hard way (and maybe you should do it at least once to learn) like described here, but in the meantime the awesome maven guys provided a tooling to generate a maven archetype project out of existing ones. 

That means if you have your maven project already set up, it is a piece of cake to create an archetype project. The magic spell is  mvn archetype:create-from-project.

I would advise you to try out this command and look into the target/generated-sources/.
You'll discover that even creating an archetype is almost for free. More information on that stuff is provided here.

Keep in mind that you will have to have at least two pom.xml, one for your artifact (your template) and one for the archetype itself. Those two poms will have different responsibilities and hence different dependencies, parents and so on. Tip:  create first a properly working prototype of your template, and only then start to "archetype" it. Typically, your archetype's pom will be rather simple, whilst the pom of your template project can be very complex.

You can provide your own parameters and do lots of things to parameterize your archetype, but this is out of scope for now.

How to get my open source project into Maven Central?


Archetypes are deployed like any other artifact in the central repository, there is no special difference to pay attention to. That means you should follow the guide to releasing artifacts in maven central.

In short, you just have to create an account on the sonatype nexus service and configure your settings.xml and your pom with a fixed parent. By "extending" the Sonatype OSS Parent POM you'll get magically everything you need to publish your project to public available Snapshot and Release Repositories.

For example, if you want to publish a Snapshot version of your application, a simple mvn deploy suffices.

To publish a release, you have to enter three commands:

  • mvn release:clean
  • mvn release:prepare
  • mvn release:perform

After that, there is some manual step (which can also be automated) and then your artifact will be hosted on Maven Central, which means that for every maven user on the world your library is readily available by providing your groupId, artifactid and version number.

But wait - where is JavaFX here?


Neither JavaFX nor Scala have anything to do with maven archetypes or deploying artifacts to maven central. You could write an artifact for your next great project idea using your favorite technologies, just like I did for the scala-javafx-archetype.

This archetype sets up a properly configured maven project using Scala and JavaFX, to try yourself you need a recent JDK and maven installed. Moreover you will need the JavaFX libraries in your classpath, with JDK8 this will be the default.

If this applies to you, you can jumpstart into JavaFX development with Scala by entering the following in your command line:

mvn archetype:generate -DarchetypeGroupId=net.ladstatt -DarchetypeArtifactId=scala-javafx-archetype -DarchetypeVersion=0.1

For more information visit the github repository.

Wednesday, December 5, 2012

CUDA 101

At the moment I'm spending some spare time doing CUDA programming

Spending most of my time with Scala, it would be nice if I could exploit the graphics card also in this language,  at the moment  some very smart guys are exactly doing this with ScalaCL, which I will definitely have a closer look at in the near future.

Anyhow, I started with the hello world program, vector addition, and my first experiments look promising. If you have to solve problems which are independent from each other and lend themselves for parallel programming, you can achieve very good results. Well, who would have thought that. ;-)

runtimes for an example cuda program

In the example above, a runtime measurement of a simple CUDA program is shown. The first line shows the runtime for 1024 threads, the second one for 512 and the last one for 256 threads. It's interesting to see the difference between 512 and 256 threads compared to the rather small difference between 1024 and 512 threads. 

My point is that you can expect a considerable performance gain if you tune your calculations using the power of the gpu. As always, one has to create means for parameterization, but, even more important, use them to actually to balance the system appropriately.

Of course, those guys already have done programming GPU 101.



Tuesday, December 4, 2012

Long time, no blog post.

It seems this blog walks the same way like my other 4 did. The reasons for not having written my precious thoughts to the world are in part lack of time, lack of nice ideas and / or considerations about copyrights.

Something else:

Only just recently I've discovered Coursera, a website dedicated to online learning.

I've participated in the course "Functional Programming Principles in Scala" and was very pleased with both the contents of the course, the organization, the grading system  and the assignments.

I was one of the 10.000 people who got a certificate. Hooray!


Maybe you want to read the retrospective of the course itself rather than this here.