Where to place module-info.java using Java 9?

前端 未结 3 1554
無奈伤痛
無奈伤痛 2021-02-19 03:33

I have an OSGI application and I have around 30 bundles (jar files). Today I decided to see how it works/if it works with Java 9.

So I started my application and got

3条回答
  •  长发绾君心
    2021-02-19 03:46

    Generic tips:

    • You should read the State of the Module System to familiarize yourself with the JPMS. Alternatively, have a look at this module system tutorial (disclaimer: I'm the author).
    • As described in the answer to your other question, there is no need to create modules if you don't want to.

    To answer your specific questions:

    The module declaration (module-info.java) needs to go into your source root directory (e.g. src/main/java). It then has to be among the list of files to compile, so it will get turned into a module descriptor (module-info.class). Last step is to include it in the list of class files that are packaged into a JAR. (Having a module descriptor in a JAR turns it into a modular JAR. If placed on the module path, the JPMS turns it into a module.)

    If you don't want to create modules after all and prefer your code to run in the unnamed module, you can allow it to access internal APIs with the placeholder ALL-UNNAMED - in the case f your warning you need to open that package to reflection:

    --add-opens java.base/java.net=ALL-UNNAMED
    

    The better solution would be to stop using internal APIs, though.

提交回复
热议问题