在默认包中的JAR文件中导入类 [英] Importing classes inside JAR files that are in the default package

查看:125
本文介绍了在默认包中的JAR文件中导入类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在这里使用队列?

How do I use Queue here?

我不能让导入工作,因为Queue.class不在包中。

I can't get the import to work because Queue.class is not in a package.

我已尝试过这个宇宙中的一切,而且还有更多。

I have tried everything in this universe, and more.


http://i.stack.imgur.com/AFrrc.jpg

推荐答案

您的 Queue class是未命名的包(请参阅 JLS )。无法导入。另外,这是不好的做法。

Your Queue class is under unnamed package (refer JLS). It can't be imported. Also, it's bad practice.

您有两个选项


  1. 将您自己的代码移动到未命名的包。理论上来说,他们都是在同一个包中,你不需要导入 Queue ,因为它的类名足以找出这个类。

  1. Move your own code to unnamed package. Theoretically, both of them being in same package, you will not need to import Queue as it's class-name is suffice to find out the class.

使用 JarJar - 一种工具来重新包装您的jar文件。重新包装包含 Queue 类的jar,并将未命名的包移动到一个明智的包名称。使用完全合格的类名(FQCN)导入。

Use JarJar - a tool to repackage your Jar files. Repackage the Jar containing the Queue class and move the unnamed package to a sensible package name. Use Fully Qualified Class Name (FQCN) to import.

我建议使用软件包,然后选择选项2。

I would suggest to use packages and go for option 2.

编辑1 :也可以看到这个在Java中的默认包中导入类的语法是什么?

这篇关于在默认包中的JAR文件中导入类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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