Jigsaw: From Hello World to WorldClock
(last updated 2010-06-20)
Moving on from Hello World to WorldClock, a simple multimodules application.
1. Get the source
Install Subversion:
sudo apt-get install subversion
Create the directories:
mkdir -p ~/dev/worldclock
Get the source:
cd ~/dev/worldclock
svn checkout https://worldclock-application.dev.java.net/svn/worldclock-application/tags/application6-jigsaw ~/dev/worldclock/application –username guest
When prompted for guest password just press enter, Gnome keyring application then pops up, just cancel and say yes to store the password unencrypted.
2. Move the source files arround
Create the additional directories:
mkdir -p ~/dev/worldclock/application/attic
mkdir -p ~/dev/worldclock/application/build
mkdir -p ~/dev/worldclock/application/resources/lh/worldclock
mkdir -p ~/dev/worldclock/application/src/lh.worldclock.application
mkdir -p ~/dev/worldclock/panel/build
mkdir -p ~/dev/worldclock/panel/resources/lh/worldclock/core
mkdir -p ~/dev/worldclock/panel/src/lh.worldclock.panel/lh/worldclock
(attic is only used to store existing files that won’t be needed)
Then move the files:
mv ~/dev/worldclock/application/*.* > ~/dev/worldclock/application/attic
mv ~/dev/worldclock/application/src/META-INF ~/dev/worldclock/application/attic
mv ~/dev/worldclock/application/src/lh ~/dev/worldclock/application/src/lh.worldclock.application
mv ~/dev/worldclock/application/src/lh.worldclock.application/lh/worldclock/core ~/dev/worldclock/panel/src/lh.worldclock.panel/lh/worldclock
mv ~/dev/worldclock/application/src/lh.worldclock.application/lh/worldclock/*.properties ~/dev/worldclock/application/resources/lh/worldclock
mv ~/dev/worldclock/application/src/lh.worldclock.application/lh/worldclock/*.png ~/dev/worldclock/application/resources/lh/worldclock
mv ~/dev/worldclock/panel/src/lh.worldclock.panel/lh/worldclock/core/*.jpg ~/dev/worldclock/panel/resources/lh/worldclock/core
The tree should look like this:
So we now have 2 subprojects: application and panel
Each composed of 3 areas: build, src and resources
3. Add the Jigsaw layer
The first part is already there, the first level of subdirectories in the src directories represents the modules roots.
Next add the module-info file for lh.worldclock.panel:
( gedit ~/dev/worldclock/panel/src/lh.worldclock.panel/module-info.java& )
module lh.worldclock.panel @ 0.7
{
requires jdk.desktop;
}
And the module-info file for lh.worldclock.application:
( gedit ~/dev/worldclock/application/src/lh.worldclock.application/module-info.java& )
module lh.worldclock.application @ 0.7
{
requires jdk.desktop;
requires lh.worldclock.panel @ 0.7;
class lh.worldclock.WorldClock;
}
4. Create the library
$JIG/bin/jmod create -L ~/dev/worldclock/modules
5. Compile and add to the library
Panel:
cd ~/dev/worldclock/panel
$JIG/bin/javac -encoding UTF-8 -source 7 -d build src/lh.worldclock.panel/module-info.java src/lh.worldclock.panel/lh/worldclock/core/WorldClockBoard.java
$JIG/bin/jmod -L ~/dev/worldclock/modules install ~/dev/worldclock/panel/build -r ~/dev/worldclock/panel/resources lh.worldclock.panel
Application:
cd ~/dev/worldclock/application
$JIG/bin/javac -L ../modules -source 7 -d build src/lh.worldclock.application/module-info.java src/lh.worldclock.application/lh/*/*.java
$JIG/bin/jmod -L ~/dev/worldclock/modules install ~/dev/worldclock/application/build -r ~/dev/worldclock/application/resources lh.worldclock.application
6. Run
$JIG/bin/java -L ~/dev/worldclock/modules -m lh.worldclock.application