【问题标题】:Importing External .jar file to Eclipse when the package name of the .jar file is (default package)当 .jar 文件的包名为(默认包)时,将外部 .jar 文件导入 Eclipse
【发布时间】:2018-03-08 09:56:11
【问题描述】:


我将一个 jar 文件导入 Eclipse。

因此,在 Eclipse 中,通过右键单击项目 → 构建路径 → 配置构建路径。在库选项卡下,单击添加外部 JAR 并提供 Jar 文件。

现在我可以在 “Package Explorer”“Referenced Libraries” 中看到它。
在像"common-math.jar"这样的.jar文件中,有很多像"org.apache.commons-math"这样的包,我们可以导入这些包在我们使用它们的代码中。
但是在我添加的.jar 文件中,只有一个包的包名是(默认包)。如何将其导入到我的代码中?
此代码有错误:

导入(默认包).xxxxxxxx;
令牌上的语法错误,应改为名称

My Jar file
我也看到how to determine package name of a class in a jar file

【问题讨论】:

    标签: java eclipse import jar


    【解决方案1】:

    (默认包)表示jar中的类没有任何包。要从 jar 中导入 SomeClass 类,您只需要

    import SomeClass;
    

    没有用包名限定它。

    【讨论】:

    • 层次结构为:Referenced Libraries -> armstrong.jar -> (default package) -> Armstrong.class。 ** import Armstrong;** 无法解析。
    猜你喜欢
    • 1970-01-01
    • 2011-06-26
    • 2011-09-18
    • 2011-05-24
    • 2014-09-27
    • 2014-12-03
    • 2014-10-20
    • 2014-09-03
    • 2013-06-08
    相关资源
    最近更新 更多