Skip to content
Advertisement

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

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

JavaScript

After some reading I added command line option

JavaScript

and created file module-info.java with the following content:

JavaScript

And I have two questions. Where should I place this module-info.java to make jvm read it? How should I bind this module-info with org.apache.felix.framework-5.4.0.jar file/bundle/jar?

If I do everything wrong please, show me right direction for fixing this problem.

Advertisement

Answer

Generic tips:

To answer your specific questions:

Place module declaration (module-info.java) into the project’s source root directory (e.g. src/main/java). It must be among the list of files to compile to be 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:

JavaScript

The better solution would be to stop using internal APIs, though. 😉 As this is not your code, but your dependency, you should look for or open an issue with Apache Felix that asks to remove the access of internal API.

Advertisement