Wednesday, October 8, 2008
Getting Started With OSGi
at work, the new project is a set of different collaborating web application using our usual stack of spring, hibernate and wicket. so we had a look at different platforms that supports this kind of apps, and we found that springsource dm server fitted our needs best. unfortunately some of our customers require us to run the apps on a websphere application server, so we had to drop springsource dm server and with it the whole OSGi solution was dropped. we all weren't happy, as all other solutions were so far behind OSGi.
anyway, i decided to learn more about OSGi for personal interest. currently i'm reading Neil Bartlett's free book OSGi in Practice. There aren't that many sources about OSGi at the moment, but although Neil's book is currently in draft state, it's quite worth a read. Thanks Neil.
Monday, September 15, 2008
sources of information
my primary source of information is reading news and blogs from the internet. i collect these news as feeds (rss or atom) with google reader. currently i have registered about 20 feeds, which i group in the first place by categories as 'daily feeds' and 'none daily feeds'. i try to read all the incoming 'daily feeds' every day, while i read the others when i get the time to. some of my favorite daily feeds are from dzone, theserverside, javalobby, slashdot, ibm developerworks and sun developer center. many of these news i mainly skip through - probably about 80 percent. of the remaining 20% there are sometimes some items which are especially interesting to me. i store these in google reader by marking them with a star. some posts on special topics (currently for example javafx or scala) i store in separate categories.
another information store is my google mail account. whenever i find any special articles outside of my news feeds or other documents/tutorials (e.g. in pdf format) i store links to these or the documents themselves in my google mail account. sometimes i also create link collections on a special topic. i store a set of keywords with each mail. currently i'm also trying out a personal wiki(mediawiki) for a better structuring of these collected information than it is possible with emails.
another source of information is, of course, books. i don't read books on a regular basis, but i read about three or four books a year. the latest were 'effective java', 'hibernate in action' and 'pojos in action'.
last but not least i listen to the java posse podcast, which is really great.
so all inall this might seem a lot of information. but actually i have a lot of time driving to work and home again by train.
Tuesday, September 2, 2008
Maven Integration Tests with Jetty and Selenium
overview
this solution works in the following way:
- create two maven modules: one for the webapp, one for the integration tests
- install the war-file of the webapp to your maven repository
- in the integration test project set up the selenium/junit tests
- configure the surefire plugin to run the tests only in the integration-test phase
- use the maven-dependency plugin to download and unpack the war-file to the target directory of the integration-test project
- run the unpacked webapp with the jetty plugin
- start the selenium server with the selenium plugin
- run the integration tests
the details
set up the multi-module project
first of all, make your maven project a multi-module project in order to run the integration tests in a separate module apart from you ordinary junit tests. so you'll have three projects: a webapp-parent project, a webapp (war) project and a webapp-integration-tests (jar) project. for more information on setting up a multi-module project see the definitive guide to maven. here are excertps of the projects' poms:
webapp-parent pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>de.foo.webapp</groupId>
<artifactId>webapp-parent</artifactId>
<packaging>pom</packaging>
<name>WebApp Parent</name>
<version>1.0</version>
<modules>
<module>../webapp</module>
<module>../webapp-integration-tests</module>
</modules>
...
webapp pom.xml. the webapp-integration-tests is like this but packaging is jar:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>de.foo.webapp</groupId>
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<name>WebApp</name>
<parent>
<groupId>de.foo.webapp</groupId>
<artifactId>webapp-parent</artifactId>
<version>1.0</version>
</parent>
...
unpack the war file
in most cases the maven jetty plugin is used to run the the project it is configured for as a webapp. in this case we'll configure the jetty plugin in the integration-tests project to run the webapp project's generated war-file. to do so, the web app war has to be installed to your local repository (run mvn install). this war file can be fetched and unpacked in the integration-tests project with the maven dependency plugin:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dependency-maven-plugin</artifactId>
<executions>
<execution>
<id>get war</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>de.foo.webapp</groupId>
<artifactId>webapp</artifactId>
<version>1.0</version>
<type>war</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/webapp/webapp</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
...
set up the jetty plugin
first, tell the jetty plugin to run the unpacked war-file by placing a jetty.xml file in the src/test/resources folder of the integration-tests project which defines the webapp directory. you can use the default jetty.xml and set the webAppDir parameter to point to the target directory:
<Set name="webAppDir">target/webapp</Set>. then in the pom.xml configure the jetty plugin to run in the pre-integration-test phase.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<daemon>true</daemon>
<webApp>target</webApp>
<jettyConfig>target/test-classes/jetty.xml</jettyConfig>
</configuration>
<executions>
<execution>
<id>start jetty server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war</goal>
</goals>
</execution>
</executions>
</plugin>
...
you can try maven integration-test or maven jetty:run-war to see if this works as expected (set the daemon parameter to false before trying this).
set up the selenium plugin
the selenium plugin then starts a selenium server in the pre-integration-test phase, too. keep in mind that the configured maven goals run in the order they were defined in the pom.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</execution>
<execution>
<id>stop selenium server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
</plugin>
set up the tests
next, move your integration tests to src/test/java in the integration-tests project. these can be run with the maven surefire plugin. this has to be configured to run the tests only in the integration-test phase.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skipTests>false</skipTests>
</configuration>
</execution>
</executions>
</plugin>
that's it. call maven integration-test to run the tests.
Tuesday, August 12, 2008
effective java
this book is still great.
won an eclipse t-shirt
thanks to eclipse. this is my first developer t-shirt.
Thursday, June 26, 2008
scala functional programming
def plus1(a : Int) : Int = 1 + a
it takes an argument
a
of type Int
and returns 1 + a
(you guessed it). you can call this function like plus1(2)
. [you could have enclosed the body of the function in curly braces, but it's just one expression, so you don't have to]so, now let's define a higher-order function. that's a function which takes another function as parameter or returns a function.
def doWithInt(a : Int, f : Int => Int) : Int = f(a)
this is a function that takes an
Int
as first parameter and a function type as second. the parameter f
is a function of type Int => Int
which takes an Int
as parameter and returns an Int
. this function simply applies the function f
to the parameter a
. you could call this function passing to it a reference to the function plus1
declared before: doWithInt(3, plus1)
. this will return 4
as it applies plus1
to 3
. so, these are just the basics of functional programming with scala. things can become quite weird when it comes to more complex higher-order functions, e.g. function returning functions, currying or recursion. have a look at 'Scala By Example' for examples.
one thing i forgot to mentioned is some syntactic sugar for the example above. instead of calling
doWithInt(3, plus1)
you could have equally donedoWithInt(3, 1 +)
this is because
+
is a member function of the type Int
, as seen in a previous post.so, that's it for this post then. more on functional programming with scala coming soon.
Wednesday, June 25, 2008
eclipse ganymede release
i like the new modelling features, especially because i've been waiting so long for some (free) support in that area in eclipse. all the uml plugins i've tried so far were either quite limited in their functionality or their usability. but now all sorts of uml diagrams are supported, e.g. class diagrams, activity diagrams, use case diagrams, etc. What's missing are some kind of reverse engineering features and sequence diagrams (or i haven't found them yet).
the new breadcrumbs feature shows the path to the current item at the top of the editor. it's like
project -> src folder -> package -> class -> class member
. each of these crumbs has a context menu which shows other items at the chosen level. i think that's quite nice, as it allows more context-sensitive working like mylyn task focussing, which makes it easier to find items than in the package/project explorer.javascript support has been greatly improved. it now offers many features known from the java perspective. For example you can follow function calls by pressing F3 oder holding Ctrl and clicking on a method call. you can display the call hierarchy of functions and there is refactoring support, e.g. renaming functions.
one thing i'm still waiting for is a mylyn feature that allows for creating reports, e.g. a report that lists all completed tasks per week with estimated time and actual time. sadly, mylyn hasn't been improved that much, i think. but still it's a great feature.
these are just some of the new features and improvements. there are many smaller ones, like junit test excectution time, enhanced tooltips (e.g. javadoc on types), autocompletion, subversion support, etc.
one feature i haven't tried out so far is the ECF (eclipse communication framework), but that is one i'll try out for sure. from what i've read, it seems to support remote team collaboration, e.g. to share an editor. that sounds interesting.
Friday, June 20, 2008
quicksort source code
google syntaxhighlighter
public static void swap(int[] a, int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
Tuesday, June 10, 2008
quicksort java scala groovy
java: 280 ms
scala: 359 ms
groovy: 535250 ms
Thursday, June 5, 2008
first look at scala
scala runs on the jvm and the syntax should be quite familiar to java developers. hello world in scala looks like this:
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
there are some interesting things about this. first, the object declaration means that HelloWorld is a singleton object. that is also why the main 'method' is not declared static. as HelloWorld is a singleton main is 'globally available' and doesn't need to be static. static members (methods) or fields do not exist in scala. second, main doesn't declare a return type. it's called a procedure method.
as said, scala runs on the jvm. because of that scala classes can interact with existing java classes. for example you can import and use java classes:
import java.util.{Date, Locale}
import java.text.DateFormat
import java.text.DateFormat._
these import statements show that you can import multiple classes from one packge with that curly braces notation. and you can import all names from a package or class with the underscore notation. the above import makes members of DateFormat available, so you can call the static method getDateInstance() directly. Why not use the * notation for the imports? * is a valid identifier in scala. you'll see why, soon.
Methods with a single argument can be called in infix syntax in scala that means the method format of DateFormat can be called like in the following example:
val now = new Date
val df = getDateInstance()
val str = df format now
this call is equivalent to df.format(now). at the first look this is not quite an interesting feature but it offers some possibilities, one of which i'll show next. in scala 'everything is an object', e.g. primitive types as well. then remember that * is a valid identifier and the infix
syntax for methods. then look at this code and try to figure out how it works:
2 + 3 * 4 / 2
this is equivalent to
2.+(3.*(4./(2)))
all the integers are objects and the operators are methods of these objects. operators are method calls.
this was my first look at scala. more looks coming soon, for sure ...
Monday, June 2, 2008
staying up to date
Friday, May 16, 2008
far behind
This is simply too much. Seems like I have to wait and see what is really important.
Thursday, March 6, 2008
no time
Wednesday, February 27, 2008
javascript is dirty
one possibility would be to append the javascript to the component markup. this way it would be executed whenever the component is rendered. but what about the placeholders in that script? he said, he could use wicket label components in the javascript that does not render its tag (e.g. a span) but only its body.
after all javascript would be a dirty language anyway (e.g. because of browser incompability), so why not try this dirty approach.
Friday, February 15, 2008
grails orm (gorm)
consider a domain model class user which has properties birthday and username. you can then query data calling User.findByUsername(uname) or User.findByUsernameLike(uname) or even User.findByUsernameAndBirthdayLessThan(uname, beforeDate) without implementing or even declaring these methods in any way - they are generated dynamically at runtime and this is mainly possible because of groovy`s dynamic features.
checking out grails
the project starts creating an empty domain model class which actually grails creates for you from the command line. then you need to fill this class with its properties. grails can then create all other components (view, controller, persistence, tests, ...) for you either using scaffolding (i.e. components are generated at runtime) or by generating the according groovy files. the generated artefacts are created based on useful defaults (the basic crud actions are implemented) and can be customized by the developer later on.
all in all i`m very confident with what i`m able to do with grails after only one week. but i think what helped very much is that i`m a bit familiar with the frameworks used by grails (groovy/java, spring, spring mvc, hibernate). the next days will go on learning grails and have a deeper look into the details of the different layers.
beginning groovy
groovy is a dynamic programming language that runs on the JVM and it´s quite easy to learn for java programmers. as it runs on the jvm you can use existing java libraries in groovy as well as you can use groovy scripts in your java applications which at the moment seems the main use case to me. mainly due to its dynamic features groovy offers more flexibility and an increased productivity opposed to java in some cases, which is probably the primary goal of groovy. in other cases you will probably miss some of java´s features (mainly static typing).
my first impression of groovy is that with some experience you can do simple things really fast, for example text/data processing. in this case groovy comes with really helpful features like improved support for regular expressions, closures, builders, native support of lists and maps, ranges and groovy strings.
maybe the next days i will get into details of some the coolest features of groovy, e.g. closures, and when i feel experienced enough i`ll try grails, a groovy web application framework.
first post
in the first place i start this blog as a personal blog to record the history of my (hopefully) growing experience in software development. my background: i started web development about one year ago. so my experience in this area is not quite big. but maybe this is why this blog could become interesting.
currently my company is developing web applications using java. we use wicket for the front end, spring for the business tier and hibernate for persistence.