Thursday, September 27, 2007

How to quick start wicket project for rapid java web application development (with maven and jetty)

I walked by a friend at school few days ago and noticed he was working on a pet project. I looked over his shoulder for a while and saw he was using PHP and Apache as his development platform. Me, being the Java fan that I am, told him I had always dreamed of writing a little article on how to jump start Java web application since few of my very capable friends haven't been able to dive into Java web development due to the complexity it takes to write the applications, test and deploy them. So I started writing the article yesterday. I started writing and went on and on about maven and how great that is until I hit the preview button and noticed it had turned into ~2 pages worth of maven praising. I'm not going to publish that article, instead I'm going straight to the point.

So to summarize the article that never got, nor will get published:

  1. Get the latest JDK, currently JDK 6 update 2, if you don't have any JDK setup. The article will be written with Java 5 in mind (post-publish editing)
  2. Get maven and read at least the 5 minute test and the getting started tutorial
  3. Maven rocks
  4. Learn to use a shell

So I'm going to show you how to setup the project itself and maybe I'll write another article soon on how to create a very simple image gallery using that setup.

First of all, let's create the project by running the following command from whatever directory you want the project folder to be created in: mvn archetype:create -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId=wicket-archetype-quickstart -DarchetypeVersion=1.3.0-beta3 -DgroupId=com.foursongs -DartifactId=gallery (one liner)

Now run mvn jetty:run in shell from inside the gallery directory and visit the local wicket website which should be running on your computer by now. Wasn't that easy and painless? Jetty serves up whatever you dish up in your quickstart application without any setup at all.

Before we start programming I recommend you pull up your favourite IDE such as eclipse or intellij and let maven generate a project for you. Stop jetty by pressing ctrl+c and write mvn eclipse:eclipse if you want eclipse project or mvn idea:idea if you want intellij project generated. After that, fire up your IDE, open the new project maven created for you and hack away.

I hope this shows that kick starting a Java web application isn't all that difficult. I recommend you head over to the wicket website and maybe the wicket library website for some example of what wicket can do and what you can do with wicket. Don't hesitate to leave comments if you have any questions regarding maven or wicket.

Sunday, September 23, 2007

A little nip there and tuck here

Þá er komið að því að skera upp útlitið á síðunni. Fyrsta skrefið er að setja einfaldara sniðmát í gagnið (check!). Einfaldasta sniðmátið sem blogger bíður upp á er þetta eins dálks umbrot sem þú, lesandi góður, starir á núna, fyrir utan smá viðbætur; ég stillti það til að vera miðjað og í fastri vídd.

Næsta skref verður að vefa eitthvað viðmót sjálfur, setja smá skraut hér og þar. Sjáum til hvað verður úr því, ég hef ekki mótað síðuna nægilega mikið (núll) en ég hef lengi haft augun á breytilegri umbrotstækni. Kannski ég reyni að koma einhverju meiru fyrir á síðunni áður en ég fer að flytja hluti á milli dálka eftir því hvaða skjáupplausn lesandinn er með?

Geymum fítusana aðeins... Ég fer að vinna í að koma meira efni inn á síðuna ásamt því að vefa einhverja vitleysu í frítímanum, hressa upp á CSS kunnáttuna mína.

Annars er allt gott að frétta úr Grafarholtinu. Við erum með nokkuð gott útsýni út um gluggann í kotinu okkar og höfum tekið eftir því undanfarið að það er nýjasta tíska hjá hundaeigendum að fara með hundinn út og leyfa honum að spretta á götunni á meðan eigandinn situr í bílnum og keyrir á eftir hundinum. Þetta er alveg frábær sjón! Djöfull er fólk orðið latt við að hreyfa sig ef það getur ekki einu sinni drullast til að fara með hundinnn í göngutúr.

Þangað til næst...

Thursday, September 13, 2007

How to solve maven jaxb dependency troubles

If you use maven, as I do, on Java 6 you might experience a slight hiccup when using JAXB in your project and deploying that to Java 5, perhaps because JAXB is endorsed library in Java 6.

I had one of those hiccups few days ago when I deployed an application to a server with Java 5. When tomcat loaded, I saw a ClassNotFoundException in my logs, specifically missing a JAXBException class.

This is of course no big deal since one just fires up firefox, visits e.g. mvnrepository.com and searches for JAXB. Have you seen the results for JAXB on mvnrepository.com? Hope not... There's no instant way of telling which combo is going to do the trick for you. You try out a few combos, probably one -api and one -impl and see how things go. If you're unlucky, not selecting the correct combo, you google and find out that java.net hosts its own maven repository which makes you think they have the solution to your problem, since they host JAXB poms over there. Which of course isn't true, so you unsuccessfully try them out as well.

To save you some trouble I give you a combination that works, without any extra repositories added:

    <dependency>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
      <version>2.0</version>
    </dependency>
   <dependency>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-impl</artifactId>
      <version>2.0.2</version>
    </dependency>

It's no fun debugging this sort of problem at 4am...

About Me

Árni Hermann Reynisson
Ég nem hugbúnaðarverkfræði við Háskólann í Reykjavík. Ég vinn sem forritari hjá Hugsmiðjunni. Skoðanirnar sem birtast á síðunni eru mínar skoðanir og endurspegla ekki endilega skoðanir atvinnuveitanda míns. Takk fyrir innlitið.
View my complete profile

Greinar í tímaröð