包不可见错误 [英] Package is not visible error

查看:68
本文介绍了包不可见错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在项目中使用joptsimple软件包,但出现以下错误:

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.internal.joptsimple is declared in module jdk.internal.opt, which does not export it to the unnamed module)

任何想法我该怎么办?

推荐答案

好吧,消息清楚地显示了(实际上,请注意JDK开发人员"内部"的漂亮命名约定,这意味着他们不需要公开),您尝试访问的API位于一个软件包中,该软件包不会导出到除这些模块之外的任何其他模块-

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

即使您在声明中添加了requires jdk.internal.opt模块.

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

应避免使用这些软件包中的类.

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

此外,由于甚至 Open JDK本身也集成了JOpt Simple供内部使用 .我建议您使用库

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-

<dependency>
    <groupId>net.sf.jopt-simple</groupId>
    <artifactId>jopt-simple</artifactId>
    <version>6.0-alpha-2</version>
</dependency>

等级:-

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

包括在您的类中的正在使用的程序包名称后,只需 joptsimple.* ,而不是 jdk.internal.joptsimple.* .

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

这篇关于包不可见错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆