On 14.10.15 18:48, Alan Bateman wrote:
On 14/10/2015 17:14, Philippe Marschall wrote:
Hi

I'm looking for an up to date syntax documentation for the
module-info.java. Specifically I'm looking for the syntax for optional
dependencies and specifying the main class. The most up to date
information I could find was [1] but this doesn't cover optional
dependencies. Googling suggests the following syntax

require optional module-name;

But this doesn't seem to work. Googling also suggests there is/was
syntax for specifying the main class but none of the example seem to
work anymore.

The main project page [1] has links to all the current documents,
including the draft "Modules in the Java Language and JVM" page.

I suspect it may be a surprise but there isn't any support for optional
dependences in the proposed design or prototype. At least for the JDK
modularization effort then we've been able to mostly eliminate the
original needs for this by moving to services.

Most of my needs for optional dependencies come from annotations. Three examples come to mind: 1. Lifecycle annotations like (javax.annotation): If code runs within some container often methods with such annotations are detected and automatically invoked at the right time. But if the same code runs outside a container the annotations are not needed and the methods can simply be invoked explicitly. 2. Additional type check annotations (eg. JSR-305): These annotations are not needed at runtime but still need to be in the class files for tools to perform static analysis. Generally all annotations with a retention policy of class are candidates for optional dependencies. 3. Mapping annotations: Sometimes classes have annotations for specific mapping technologies. But if they are used without these mapping technologies then the annotations are not needed at runtime.

The module main class is not in the module declaration. If you are
building a modular JAR then you can specify it to the jar command with
--main-class $MAINCLASS. If the initial module is exploded on the file
system then you can specify the main class to the java launcher with -m
$MODULE/$MAINCLASS.

Where in the JAR does this information end up?

Cheers
Philippe

Reply via email to