Hi

I don't know if it already exists somewhere, but it shouldn't be hard to
create a main method that's loaded with -jar which then bootstraps all the
modules found inside the jar file.
For instance, say all your modules are inside your fatjar.jar!/mods
directory, and you have the name of the main module / main class, then
something like this might work:

FileSystem fs = // create zip fs of the fatjar.jar
finder =
ModuleFinder.of(Files.walk(fs.getPath("/mods/")).toArray(Path[]::new));
config = Layer.boot().configuration().resolveRequires(finder,
ModuleFinder.of(), Set.of(mainModuleName));
layer =
Layer.boot().defineModulesWithOneLoader(config,
ClassLoader.getSystemClassLoader());

layer.findLoader(mainModuleName).loadClass(mainClassName).getDeclaredMethod("main",
String[].class).invoke(null, args);

/Michael

On 18 November 2016 at 23:40, <org.open...@io7m.com> wrote:

> Hello!
>
> When I write command line applications, I typically produce an
> additional platform-independent "onejar" for convenience. More
> specifically, I use the Maven Shade plugin to pack all of the classes
> of all of the dependencies into a single jar with MainClass attribute.
> The main benefit of doing things this way is that the jar file remains
> platform independent (assuming that the code itself is platform
> independent). A good example of this is my kstructural package:
>
>   http://io7m.github.io/kstructural/
>
> The main command-line jar program is an amalgamation of all of the
> other modules and all dependencies:
>
>   https://repo1.maven.org/maven2//com/io7m/kstructural/
> io7m-kstructural-cmdline/0.3.0/io7m-kstructural-cmdline-0.3.0-main.jar
>
> Is there already a facility to do this under Jigsaw? Jlink is not quite
> what I'm looking for in this case, because the produced artifacts would
> be platform-specific.
>
> Clearly, producing onejars in pre-Jigsaw Java is like taking all of the
> problems of the classpath and smashing them into one unfixable lump for
> deployment. The fact that we often get builds that appear to work using
> this method seems to owe a lot to blind luck.
>
> No doubt doing this sort of transformation is a hell of a lot safer when
> there are module boundaries to work with, services declared in module
> descriptors, and so on.
>
> I suspect I could address the same question to the Maven Shade list,
> but I thought I'd better check here first. :)
>
> M
>

Reply via email to