Sunday, 7 March 2010

Hello World module with Jigsaw

Following my building Jigsaw post, here are the instructions for a Hello World module:

1. Create the project structure

mkdir -p ~/dev/hello/src/hello/lh/hello
mkdir -p ~/dev/hello/build

2. Create the Main class
use: gedit ~/dev/hello/src/hello/lh/hello/Main.java & 
package lh.hello;

public class Main
{
  public static void main(String[] args)
  {
    System.out.println("Hello Jigsaw!!");
  }
}

3. Create the module descriptor
use gedit ~/dev/hello/src/hello/module-info.java &
module hello @ 1.0
{
  class lh.hello.Main;
}

4. Compile
In ~/dev/hello :
$JIG/bin/javac -source 7 -d build src/hello/module-info.java src/hello/lh/hello/Main.java

5. Create a private modules library
Create a private library so that the module can be removed easily. The private library parent defaults to the JDK library.
In ~/dev/hello :
 $JIG/bin/jmod create -L modules

6. Install the hello module
In ~/dev/hello :
 $JIG/bin/jmod install -L modules build hello

7. Run
In ~/dev/hello :
$JIG/bin/java -L modules -m hello
prints:
Hello Jigsaw!!