Package is not visible error

前端 未结 2 622
無奈伤痛
無奈伤痛 2021-02-14 11:54

I was trying to use joptsimple package in my project but I get following error:

Error:(4, 20) java: package jdk.internal.joptsimple is not visible
  (package jdk         


        
2条回答
  •  渐次进展
    2021-02-14 12:35

    Well, the message clearly reads (in fact notice the beautiful naming convention by JDK devs "internal" meaning they don't want to expose them) that the API you're trying to access is in a package that is not exported to any other module except these -

    exports jdk.internal.joptsimple to jdk.jlink, jdk.jshell
    

    even if you add requires jdk.internal.opt module in your declaration.


    To make use of classes from these packages should be avoided.

    Also since even the Open JDK itself integrates JOpt Simple for internal usage by JDK tools. I would suggest you make use of the library jopt-simple for a long-term solution by adding the dependency on your modulepath(java9) or classpath(java8) using -

    Maven -

    
        net.sf.jopt-simple
        jopt-simple
        6.0-alpha-2
    
    

    Gradle:-

    compile 'net.sf.jopt-simple:jopt-simple:6.0-alpha-2'
    

    After the inclusion of which the package name in use in your classes shall simply be joptsimple.* instead of jdk.internal.joptsimple.*.

提交回复
热议问题