How to Declare Modules in java 9 -
i want use java 9 modules in project. want put data , service classes (in package named com.test.base
) in 1 module named (base), , put other things main class , gui (in package named com.test.main
) in module named (main).
- how declare simple module (base)?
- how declare module (main) dependency of (base) module?
i want use (base) module reflection.
assume root package
com.test
directory structure should use these modules?
the jigsaw quick-start nice place start off out. answer specific questions:
how declare simple module (base)?
create class named module-info.java
within com.test.base
directory definition as:
module base { exports com.test.base; }
this exports com.test.base
package.
how declare module (main) dependency of (base) module?
same other module base
class named module-info.java
within com.test.main
directory definition as:
module main { requires com.test.base; }
makes use of exported package.
i want use (base) module reflection.
depending on yoru usage, if api os removed or changes listed here, can use --add-exports
java option detailed in jep-261
i suggest reading nicolai's answer how solve inaccessibleobjectexception ("unable make {member} accessible: module {a} not 'opens {package}' {b}") on java 9? nice explanation on how make use of reflection in java-9.
the correct fix launch jvm follows:
--add-opens has following syntax: {a}/{package}={b} java --add-opens java.base/java.lang=all-unnamed
if reflecting code in named module, all-unnamed can replaced name.
assume root package com.test directory structure should use these modules?
your directory structure should like:
src/main/java - com.test - base - module-info.java - com/test/base/main.java - main - module-info.java - com/test/main/simpleclass.java
Comments
Post a Comment