3

working with java 9 modules, if i am using java.xml in my code...
1) i will import xml package using import statement...
2) if i don't mention that this package is required in the module declaration of my module...
- will the compilation of my module work.. ??
i would guess... no... and on mentioning that xml package is required on module-info.java... it might work.
so.. what I am wondering is... is that not redundancy... every importing package is implicitly... required. (unless i need to understand module even better)

Is there a way to mention that all imported packages are required in module declaration, other wise it could be a long list to mention in module-info.java?

2 Answers2

6

First of all, in module-info.java you mention modules, not packages. E.g. java.xml is a module which contains about 25 packages. So, if your module uses 10 packages from the java.xml module, you don't have to repeat that 10 times in module-info.java, you write requires java.xml just once. So, that huge list of dependencies is not huge actually.

If you really want to skip all those declarations, you can just not create module-info.java (but I don't recommend to do that). A module that does not have module-info.java is called an automatic module and it implicitly requires all other modules.

ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
  • that's gr8 explanation. gr8. _"However, java.xml is not in the module graph by default, so you have to pass"_ . My understanding is only `java.base` is available by default. What module graph are you referring. Any example? –  Jun 26 '17 at 08:40
  • 2
    The _java.xml_ module is included by default (try it with `java --limit-modules java.se --list-modules`), so not need to worry there. By the way, the confusion between modules and packages is why I use _italics_ for the former and `code formatting` for the latter. – Nicolai Parlog Jun 26 '17 at 15:00
  • @Nicolai You are right. I confused `java.xml` with `java.xml.bind` which is not included by default. – ZhekaKozlov Jun 26 '17 at 15:13
0

solution (workaround)

If you are bothered by having to write out each single requires again and again
-- there is a faster way to requires *all*
-- if you know Ahk & AhkSpy

  1. get AhkSpy
  2. open the module dependency
  3. capture & copy all of them by AhkSpy
  4. paste them all in module-info.java

enter image description here


sample code

(if you really dont know how to do the above, copy the following sample code may help you a bit)

  //  requires HikariCP;
  //  requires accessors.smart;
  //  requires android.json;
  requires antlr;
  //  requires assertj.core;
  requires attoparser;
  requires com.fasterxml.jackson.annotation;
  requires com.sun.istack.runtime;
  requires com.sun.xml.txw2;
  requires dom4j;
  //  requires jackson.core;
  //  requires jackson.databind;
  //  requires jackson.datatype.jdk8;
  //  requires jackson.datatype.jsr310;
  //  requires jackson.module.parameter.names;
  requires jakarta.activation;
  requires java.annotation;
  requires java.base;
  requires java.compiler;
  requires java.datatransfer;
  requires java.desktop;
  requires java.instrument;
  requires java.logging;
  requires java.management;
  requires java.management.rmi;
  requires java.naming;
  requires java.net.http;
  requires java.persistence;
  requires java.prefs;
  requires java.rmi;
  requires java.scripting;
  requires java.se;
  requires java.security.jgss;
  requires java.security.sasl;
  requires java.smartcardio;
  requires java.sql;
  requires java.sql.rowset;
  requires java.transaction;
  requires java.transaction.xa;
  requires java.xml;
  requires java.xml.bind;
  requires java.xml.crypto;
  requires jdk.accessibility;
  requires jdk.attach;
  requires jdk.charsets;
  requires jdk.compiler;
  requires jdk.crypto.cryptoki;
  requires jdk.crypto.ec;
  requires jdk.crypto.mscapi;
  requires jdk.dynalink;
  requires jdk.editpad;
  requires jdk.hotspot.agent;
  requires jdk.httpserver;
  requires jdk.internal.ed;
  requires jdk.internal.jvmstat;
  requires jdk.internal.le;
  requires jdk.internal.opt;
  requires jdk.internal.vm.ci;
  requires jdk.internal.vm.compiler;
  requires jdk.internal.vm.compiler.management;
  requires jdk.jartool;
  requires jdk.javadoc;
  requires jdk.jcmd;
  requires jdk.jconsole;
  requires jdk.jdeps;
  requires jdk.jdi;
  requires jdk.jdwp.agent;
  requires jdk.jfr;
  requires jdk.jlink;
  requires jdk.jpackage;
  requires jdk.jshell;
  requires jdk.jsobject;
  requires jdk.jstatd;
  requires jdk.localedata;
  requires jdk.management;
  requires jdk.management.agent;
  requires jdk.management.jfr;
  requires jdk.naming.dns;
  requires jdk.naming.rmi;
  requires jdk.net;
  requires jdk.nio.mapmode;
  requires jdk.random;
  requires jdk.sctp;
  requires jdk.security.auth;
  requires jdk.security.jgss;
  requires jdk.unsupported;
  requires jdk.unsupported.desktop;
  requires jdk.xml.dom;
  requires jdk.zipfs;
  //  requires json.path;
  //  requires json.smart;
  //  requires jsonassert;
  requires jul.to.slf4j;
  //  requires log4j.api;
  requires logback.classic;
  requires logback.core;
  requires lombok;
  //  requires mysql.connector.j;
  requires org.apache.logging.slf4j;
  requires org.apache.tomcat.embed.core;
  requires org.apache.tomcat.embed.el;
  requires org.apache.tomcat.embed.websocket;
  //  requires org.apiguardian.api;
  requires org.aspectj.weaver;
  requires org.glassfish.jaxb.runtime;
  //  requires org.hamcrest;
  requires org.hibernate.commons.annotations;
  requires org.hibernate.orm.core;
  requires org.hibernate.orm.envers;
  requires org.jboss.jandex;
  requires org.jboss.logging;
  requires org.joda.time;
  //  requires org.junit.jupiter;
  //  requires org.junit.jupiter.api;
  //  requires org.junit.jupiter.engine;
  //  requires org.junit.jupiter.params;
  //  requires org.junit.platform.commons;
  //  requires org.junit.platform.engine;
  //  requires org.mockito;
  //  requires org.mockito.junit.jupiter;
  //  requires org.objectweb.asm;
  //  requires org.objenesis;
  //  requires org.opentest4j;
  requires org.slf4j;
  //  requires org.xmlunit;
  requires org.yaml.snakeyaml;
  requires spring.aop;
  requires spring.aspects;
  requires spring.beans;
  requires spring.boot;
  requires spring.boot.autoconfigure;
  //  requires spring.boot.devtools;
  requires spring.boot.starter;
  requires spring.boot.starter.aop;
  requires spring.boot.starter.data.jpa;
  requires spring.boot.starter.jdbc;
  requires spring.boot.starter.json;
  requires spring.boot.starter.logging;
  //  requires spring.boot.starter.test;
  requires spring.boot.starter.thymeleaf;
  requires spring.boot.starter.tomcat;
  requires spring.boot.starter.web;
  //  requires spring.boot.test;
  //  requires spring.boot.test.autoconfigure;
  requires spring.context;
  requires spring.core;
  requires spring.data.commons;
  requires spring.data.envers;
  requires spring.data.jpa;
  requires spring.expression;
  requires spring.jcl;
  requires spring.jdbc;
  requires spring.orm;
  //  requires spring.test;
  requires spring.tx;
  requires spring.web;
  requires spring.webmvc;
  requires thymeleaf;
  requires thymeleaf.extras.java8time;
  requires thymeleaf.spring5;
  requires unbescape;

misc (-- following not important)

  • idk why Eclipse doesnt support this automatic adding import to module-info.java.
  • module-info.java is annoying in many aspects -- requires you do many more work -- idk why (not familiar with)
    • requires transitive
    • missing requires & program throws exception
    • conflict with some program design
  • Eclipse can indeed auto generate module-info.java by:
    right click the project > Configure > Create module-info.java
    but insufficient in some cases
  • related: Why is exporting the entire module not allowed?
  • [[Ahk & AhkSpy (/ AccViewer) is a good tool]]
Nor.Z
  • 555
  • 1
  • 5
  • 13