Wednesday, 18 January 2012

Jigsaw: Worldclock with the Maven plugin

Last updated: 2012-02-02

In the previous post I created a Maven plugin for Jigsaw, now I'll adapt Worldclock to use it.
The transformed source code is also available at: https://svn.java.net/svn/worldclock-application~svn/tags/application6-jigsaw-maven 


1. Create the directory
mkdir -p ~/dev/worldclock
2. Get the source
cd ~/dev/worldclock
svn checkout https://svn.java.net/svn/worldclock-application~svn/tags/application6-jigsaw ~/dev/worldclock/application

3. Cleanup
Remove the files that are not needed.
rm -rf ~/dev/worldclock/application/*.*
rm -rf ~/dev/worldclock/application/src/META-INF

4. Code adjustment
The current combinaison of Jigsaw/JDK8/Ubuntu does not support the sytem tray properly, so adjust the Worldclock.java to bypass it
gedit ~/dev/worldclock/application/src/lh/worldclock/WorldClock.java &

on line 106 replace:
if (SystemTray.isSupported())
with:
if (false)

on line 135 replace:
if (showWindowOnStart)
with:
if (true)

5. Move the source
Move the files to create the java sources for the application:
mkdir -p ~/dev/worldclock/application/src/main/java/lh.worlclock.application/lh/worldclock
mv ~/dev/worldclock/application/src/lh/worldclock/*.java ~/dev/worldclock/application/src/main/java/lh.worlclock.application/lh/worldclock
Move the application resources:
mkdir -p ~/dev/worldclock/application/src/main/resources/lh/worldclock
mv ~/dev/worldclock/application/src/lh/worldclock/*.* ~/dev/worldclock/application/src/main/resources/lh/worldclock
Move the panel source:
mkdir -p ~/dev/worldclock/panel/src/main/java/lh.worldclock.panel/lh/worldclock/core
mv ~/dev/worldclock/application/src/lh/worldclock/core/*.java ~/dev/worldclock/panel/src/main/java/lh.worldclock.panel/lh/worldclock/core
Move the panel resources:
mkdir -p ~/dev/worldclock/panel/src/main/resources/lh/worldclock/core
mv ~/dev/worldclock/application/src/lh/worldclock/core/*.jpg ~/dev/worldclock/panel/src/main/resources/lh/worldclock/core
More cleanup:
rm -rf ~/dev/worldclock/application/src/lh/worldclock/core
6. Add module-info for Panel
gedit  ~/dev/worldclock/panel/src/main/java/lh.worldclock.panel/module-info.java &

module lh.worldclock.panel @ 0.7
{
  requires jdk.base;
  requires jdk.desktop;
  exports lh.worldclock.core.*;
}

7. Add module-info for Application
gedit ~/dev/worldclock/application/src/main/java/lh.worlclock.application/module-info.java &

module lh.worldclock.application @ 0.7
{
  requires jdk.base;
  requires jdk.desktop;
  requires lh.worldclock.panel @ 0.7;
  class lh.worldclock.WorldClock;
}

8. Add the pom for Panel
gedit ~/dev/worldclock/panel/pom.xml &

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>lh.worldclock</groupId>
  <artifactId>panel</artifactId>
  <packaging>jmod</packaging>
  <version>0.7-SNAPSHOT</version>
  <name>Worldclock Panel</name>
  <url>http://worldclock-application.java.net/</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>lh.jigsaw</groupId>
                <artifactId>jigsaw-maven-plugin</artifactId>
                <version>0.1-SNAPSHOT</version>
                <extensions>true</extensions>
                <configuration>
                  <libraryDirectory>../modules</libraryDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

9. Add the pom for Application
gedit ~/dev/worldclock/application/pom.xml &

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>lh.worldclock</groupId>
  <artifactId>application</artifactId>
  <packaging>jmod</packaging>
  <version>0.7-SNAPSHOT</version>
  <name>Worldclock Application</name>
  <url>http://worldclock-application.java.net/</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
   <build>
        <plugins>
            <plugin>
                <groupId>lh.jigsaw</groupId>
                <artifactId>jigsaw-maven-plugin</artifactId>
                <version>0.1-SNAPSHOT</version>
                <extensions>true</extensions>
                <configuration>
                  <libraryDirectory>../modules</libraryDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

10. Install Panel
cd ~/dev/worldclock/panel/
mvn install

11. Install Application
cd ~/dev/worldclock/application/
mvn install

12. Run
 cd ~/dev/worldclock/application/
mvn lh.jigsaw:jigsaw-maven-plugin:run
(use ctrl+c on the console to exit)



No comments: