Module-file installation, module repositories, and native libraries
Mark Reinhold
mr at sun.com
Wed Apr 21 13:59:21 PDT 2010
I've just pushed these changes into the Jigsaw forest.
Module-file installation
The jmod command can now install the module files created by jpkg:
$ cat src/foo/module-info.java
module foo @ 1 {
requires jdk.base;
class foo.Main;
}
$ cat src/foo/foo/Main.java
package foo;
public class Main {
public static void main(String[] args) {
System.out.println("Foo!");
}
}
$ javac -d classes -modulepath classes \
> src/foo/module-info.java src/foo/foo/Main.java
$ jpkg -m classes/foo jmod foo
$ ls -l foo at 1.jmod
-rw-r--r-- 1 mr green 691 Apr 21 12:24 foo at 1.jmod
$ jmod -L mlib create
$ jmod -L mlib install foo at 1.jmod
$ jmod -L mlib ls
foo at 1
$ java -L mlib -m foo
Foo!
$
(The jmod command can still install a module from a regular classes
directory, as before.)
Module repositories
A module repository is a collection of modules published on a web
server. No special server-side code is required -- a repository is
just a collection of static files.
The new jrepo command is provided to create and maintain repositories:
$ jrepo /var/www/modules create
$ jrepo /var/www/modules add foo at 1.jmod
$ jrepo /var/www/modules ls
foo at 1
$
A module library can have a list of associated repositories from which
new modules can be downloaded and installed. New jmod subcommands are
provided to manage the repository list and their associated cached
repository catalogs:
$ jmod -L mlib create
$ jmod -L mlib add-repo http://localhost/modules
$ jmod -L mlib repos
0 http://localhost/modules/
$
The -R option to the ls subcommand lists the modules available in a
library's repositories:
$ jmod -L mlib ls
$ jmod -L mlib ls -R
foo at 1
$
The install subcommand can now install modules from repositories as
well as from module files and classes directories. The -n option
requests a "dry run", which resolves dependences and calculates
download and install sizes but doesn't actually install anything:
$ jmod -L mlib install -n foo
To install: foo at 1
627 bytes to download
610 bytes to store
$
If you omit the -n option then the requested module(s) and their
dependences, if any, are installed:
$ jmod -L mlib install foo
To install: foo at 1
627 bytes to download
610 bytes to store
$ jmod -L mlib ls
foo at 1
$ java -L mlib -m foo
Foo!
$
Installing modules via the Jigsaw API
Installing a module and its dependences from a library's repositories
is a two-step process. Using the API, you first open the library and
compute a resolution from an initial ModuleIdQuery:
import java.lang.module.ModuleSystem;
import org.openjdk.jigsaw.Library;
import org.openjdk.jigsaw.SimpleLibrary;
import org.openjdk.jigsaw.Resolution;
ModuleSystem ms = ModuleSystem.base();
Library lib = SimpleLibrary.open(LIB);
Resolution res
= lib.resolve(Arrays.asList(ms.parseModuleIdQuery("foo")));
The Resolution object records, among other things, the list of modules
to be installed, the number of bytes to be downloaded, and the space
required to install them:
out.format("To install: %s%n", res.modulesNeeded());
out.format("%d bytes to download%n", res.downloadRequired());
out.format("%d bytes to store%n", res.spaceRequired());
To proceed with the installation just pass the Resolution object to
the library's install method:
lib.install(res);
After this method returns the requested module will be available
unless, of course, an exception was thrown.
Native libraries
Module class loaders now override the findLibrary method, so native
libraries in a module can be found and linked in the usual way. See
the unit test org/openjdk/jigsaw/hello-native.sh for a simple example.
Updated javadoc: http://cr.openjdk.java.net/~mr/jigsaw/api
- Mark
More information about the jigsaw-dev
mailing list