This tutorial will show you how to develop the famous “Hello World” as a HK2 module using NetBeans 6.0/maven.
Before beginning, make sure that you have the IDE's Maven support. You can install the Maven plugin by choosing Tools > Plugins, clicking the Available Plugins tab, selecting the Maven checkbox, and clicking Install.
NetBeans actually creates a Hello world source file named App in the package se.javasolutions.hk2.HelloWorld.
By default NetBeans assumes that we are using Java 1.4 and will therefor not recognize annotations. Select Properties on the project folder and the category source. Change Source/Binary Format to 1.5/1.6. Close and re-open the project.
As you can see is an ordinary interface with an @Contract annotation.
The service instance is injected to the service field by the HK2 runtime container.
Now you can run the project.
The complete NetBeans project with sources can be downloaded here: HK2/helloworld_HK2.zip.
Feel free to send commends to rikard.thulin(at)ibs.se
- HK2 development site
- GlassFish v3 Engineering Guide
- HK2 presentation by Rikard Thulin & Ferid Sabanovic, IBS JavaSolutions