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

前端 未结 3 1559
無奈伤痛
無奈伤痛 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 04:06

    Well the Jigsaw quick start is a nice way to start off with if you're kick starting a project on Java-9.

    Where should I place this module-info.java to make jvm read it?

    Inferring your modeule name from the declaration module org.apache.felix.framework { }, you should place the module-info.java file in your project directory at:

    src/org.apache.felix.framework/module-info.java 
    

    How should I bind this module-info with org.apache.felix.framework-5.4.0.jar file/bundle/jar?

    Further to compile modules and package them(bind the module-info.class at the top level directory of your modular jar), you can use the javac and jar commands.

    Sample commands for the above would be somewhat like :

    $ javac --module-path mods -d mods/org.apache.felix.framework \
        src/org.apache.felix.framework/module-info.java src/org.apache.felix.framework/com/apache/felix/framework/Application.java
    
    
    $ jar --create --file=mlib/org.apache.felix.framework.jar \
        --main-class=com.apache.felix.framework.Application -C mods/com.apache.felix.framework
    

    And further you can execute the module using:

    $ java -p mlib -m com.apache.felix.framework
    

    Also apart from The State Module System and the Quick-Start documents, for migrating existing projects to Java-9, I would suggest you to follow the JDK9 Migration Guide which states a clear step wise transition required to adapt to Java9.

提交回复
热议问题