Skip to end of metadata
Go to start of metadata

There are normally two ways in which a module may be directly executed.  The module may be launched by name from the static repository like this:

Or, the module may be executed as a JAR file given on the command line like this:

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jun 28, 2013

    Is there any sample on how to package up a module?  What is com.your.module?  Is that like a zip file?

  2. Jul 28, 2015

    I have worked through a simple example of a static repository vs a JAR file. Execution from a JAR is not a simple zipping up of the static repository and throwing in a Dependency in the MANIFEST. The example I have has a simple test.main.MainEntry class that uses the JCommander package to parse its command line args:

    package test.main;

    import com.beust.jcommander.JCommander;

    import java.util.logging.Logger;

    public class MainEntry {
        private final static Logger log = Logger.getLogger(MainEntry.class.getName());
        public static void main(String[] args) {

            MyArgs myArgs = new MyArgs();
            JCommander cmdArgs = new JCommander(myArgs);
            cmdArgs.parse(args);
            log.info("Parsed MyArgs\n");
        }
    }

    Static Repository

    For the static module repository mode of execution create a modules directory structure like the following:

    [target 736]$ ls -R modules

    com org test

    modules/com:

    beust

    modules/com/beust:

    jcommander

    modules/com/beust/jcommander:

    main

    modules/com/beust/jcommander/main:

    jcommander-1.35.jar module.xml

    modules/org:

    jboss

    modules/org/jboss:

    logmanager

    modules/org/jboss/logmanager:

    main

    modules/org/jboss/logmanager/main:

    jboss-logmanager-2.0.0.Final.jar module.xml

    modules/test:

    main

    modules/test/main:

    exec-jar-1.0.0.jar module.xml

    The various module files are:

    [target 732]$ cat modules/com/beust/jcommander/main/module.xml 

    <?xml version="1.0" encoding="UTF-8"?>

    <module xmlns="urn:jboss:module:1.3" name="com.beust.jcommander">

        <resources>

            <resource-root path="jcommander-1.35.jar"/>

        </resources>

     

        <dependencies>

        </dependencies>

    </module>

    [target 733]$ cat modules/org/jboss/logmanager/main/module.xml 

    <?xml version="1.0" encoding="UTF-8"?>

     

    <module xmlns="urn:jboss:module:1.3" name="org.jboss.logmanager">

        <resources>

            <resource-root path="jboss-logmanager-2.0.0.Final.jar"/>

        </resources>

     

        <dependencies>

        </dependencies>

    </module>

    [target 734]$ cat modules/test/main/module.xml 

    <?xml version="1.0" encoding="UTF-8"?>

     

    <module xmlns="urn:jboss:module:1.3" name="test">

        <main-class name="test.main.MainEntry"/>

     

        <resources>

            <resource-root path="exec-jar-1.0.0.jar"/>

        </resources>

     

        <dependencies>

            <module name="org.jboss.logmanager"/>

            <module name="com.beust.jcommander"/>

        </dependencies>

    </module>

    To run, use: java -jar jboss-modules.jar -mp target/modules test

    JAR File

    To create an executable JAR module, a JAR with the following structure is needed:

    [target 735]$ jar -tf exec-jar-1.0.0.jar 

    META-INF/MANIFEST.MF

    ...

    META-INF/services/java.util.logging.LogManager

    jboss-logmanager-2.0.0.Final.jar/

    jboss-logmanager-2.0.0.Final.jar/META-INF/

    jboss-logmanager-2.0.0.Final.jar/META-INF/INDEX.LIST

    jboss-logmanager-2.0.0.Final.jar/META-INF/MANIFEST.MF

    ...

    jboss-logmanager-2.0.0.Final.jar/org/

    jboss-logmanager-2.0.0.Final.jar/org/jboss/

    jboss-logmanager-2.0.0.Final.jar/org/jboss/logmanager/

    jboss-logmanager-2.0.0.Final.jar/org/jboss/logmanager/AtomicArray.class

    ...

    jcommander-1.35.jar/

    jcommander-1.35.jar/com/

    jcommander-1.35.jar/com/beust/

    jcommander-1.35.jar/com/beust/jcommander/

    jcommander-1.35.jar/com/beust/jcommander/converters/

    jcommander-1.35.jar/com/beust/jcommander/converters/BaseConverter.class

    ...

    jcommander-1.35.jar/META-INF/

    jcommander-1.35.jar/META-INF/MANIFEST.MF

    ...

    logging.properties

    modules/

    modules/com/

    modules/com/beust/

    modules/com/beust/jcommander/

    modules/com/beust/jcommander/main/

    modules/com/beust/jcommander/main/module.xml

    modules/org/

    modules/org/jboss/

    modules/org/jboss/logmanager/

    modules/org/jboss/logmanager/main/

    modules/org/jboss/logmanager/main/module.xml

    test/

    test/main/

    test/main/MainEntry.class

    test/main/MyArgs.class

    Notes:

    • The module descriptors for the dependencies are located in a modules hierarchy in the root of the jar similar to how the static repository modules directory was structured. It must be called modules. This structure does NOT contain the module jars/resources.
    • The module jars must be unpacked into the root of the jar using the names specified for the resource-root path attribute in the module.xml descriptor. Above we see the jcommander-1.35.jar and jboss-logmanager-2.0.0.Final.jar directories are in the root of the exec-jar-1.0.0.jar with their associated jar contents included.
    • The exec-jar-1.0.0.jar/META-INF/MANIFEST.MF includes the following Dependencies attribute:
      •  Dependencies: com.beust.jcommander, org.jboss.logmanager

     This is run using java -jar jboss-modules.jar -jar exec-jar-1.0.0.jar