Worldclock on Jigsaw and HK2
In the previous post I ‘ported’ HK2 to work on Jigsaw, in this post I adapt Worldclock to use it.
Retrieving the existing code:
svn checkout https://svn.java.net/svn/worldclock-application~svn/tags/application6-jigsaw-maven ~/dev/worldclock-hk2
And the new pom and module-info:
svn checkout https://svn.kenai.com/svn/lh-playground~svn/jigsaw/worldclock-hk2 ~/dev/worldclock-hk2-downloads
Panel
Overwrite the existing pom and module info for the panel:
cp ~/dev/worldclock-hk2-downloads/panel/pom.xml ~/dev/worldclock-hk2/panel/
(update the libraryDirectory path for your set up / username,
gedit ~/dev/worldclock-hk2/panel/pom.xml &
)
cp ~/dev/worldclock-hk2-downloads/panel/src/main/java/lh.worldclock.panel/module-info.java ~/dev/worldclock-hk2/panel/src/main/java/lh.worldclock.panel/
Add the sample HK2 dependency injection contract:
mkdir -p ~/dev/worldclock-hk2/panel/src/main/java/lh.worldclock.panel/lh/worldclock/hk2/ gedit ~/dev/worldclock-hk2/panel/src/main/java/lh.worldclock.panel/lh/worldclock/hk2/PanelProvider.java &
then add the content
package lh.worldclock.hk2;
import lh.worldclock.core.WorldClockBoard;
import org.jvnet.hk2.annotations.Contract;@Contract
public interface PanelProvider
{
WorldClockBoard getPanel();
}
Add the sample HK2 dependency injection service:
gedit ~/dev/worldclock-hk2/panel/src/main/java/lh.worldclock.panel/lh/worldclock/hk2/PanelProviderImpl.java &
then add the content
package lh.worldclock.hk2;
import lh.worldclock.core.WorldClockBoard;
import org.jvnet.hk2.annotations.Service;@Service
public class PanelProviderImpl implements PanelProvider
{
@Override
public WorldClockBoard getPanel()
{
return new WorldClockBoard();
}
}
build
cd ~/dev/worldclock-hk2/panel/
mvn -Dmaven.test.skip=true clean install
(if the build fail due to invalid characters, edit the file and remove the comments
gedit ~/dev/worldclock-hk2/panel/src/main/java/lh.worldclock.panel/lh/worldclock/core/WorldClockBoard.java&
)
Application
Overwrite the existing pom and module info for the application:
cp ~/dev/worldclock-hk2-downloads/application/pom.xml ~/dev/worldclock-hk2/application/
(update the libraryDirectory path for your set up / username,
gedit ~/dev/worldclock-hk2/application/pom.xml &
)
cp ~/dev/worldclock-hk2-downloads/application/src/main/java/lh.worldclock.application/module-info.java ~/dev/worldclock-hk2/application/src/main/java/lh.worlclock.application/
Adjust WorldClockPanel:
gedit ~/dev/worldclock-hk2/application/src/main/java/lh.worlclock.application/lh/worldclock/WorldClockPanel.java &
replace constructor start with:
public WorldClockPanel(final WorldClockBoard board)
{
// board = new WorldClockBoard();
this.board = board;
Adjust WorldClockFrame:
gedit ~/dev/worldclock-hk2/application/src/main/java/lh.worlclock.application/lh/worldclock/WorldClockFrame.java &
add import
import lh.worldclock.core.WorldClockBoard;
remove the initialisation of pane
WorldClockPanel pane;
replace constructor start with:
public WorldClockFrame(ImageIcon icon, final WorldClockBoard board)
{
pane = new WorldClockPanel(board);
Adjust WorldClock
gedit ~/dev/worldclock-hk2/application/src/main/java/lh.worlclock.application/lh/worldclock/WorldClock.java &
add imports
import com.sun.enterprise.module.bootstrap.ModuleStartup;
import com.sun.enterprise.module.bootstrap.StartupContext;
import org.jvnet.hk2.annotations.Inject;
import org.jvnet.hk2.annotations.Service;
import lh.worldclock.core.WorldClockBoard;
replace class declaration
@Service
public class WorldClock implements ModuleStartup
make the frame non static
/*static*/ WorldClockFrame frame = null;
add the injection
@Inject
WorldClockBoard board;
make main method non static
make void showWindow() non static and change
frame = new WorldClockFrame(icon, board);
to add the board
make private PopupMenu createPopup() non static
add the following new methods
public void setStartupContext(StartupContext context)
{
}public void start()
{
main(new String[]{});
}public void stop()
{
}
build
cd ~/dev/worldclock-hk2/application/
mvn -Dmaven.test.skip=true clean install
Time to run:
cd ~/dev/hk2-jigsaw/jigsaw-adapter/
mvn lh.jigsaw:jigsaw-maven-plugin:run