How to use 3rd party library in Java9 module?

后端 未结 2 916
挽巷
挽巷 2020-11-28 11:19

I have some java9 module that uses 3rd party library that is not Java9 module, just a simple utility jar.

However, the compiler complains that it can\'t find a packa

2条回答
  •  萌比男神i
    2020-11-28 12:06

    To put it in simple steps, to use a 3rd party jar (e.g. log4j-api-2.9.1.jar below) in your module:-

    1. Execute the descriptor command of jar tool

       jar --file=/path/to/your/jar/log4j-api-2.9.1.jar --describe-module
      

      This would provide you an output similar to

      No module descriptor found. Derived automatic module. log4j.api@2.9.1 automatic

    2. In your module descriptor file, declare a requires to that module name as:-

       module your.module {
           requires log4j.api;
       }
      

    That's it.

提交回复
热议问题