简体   繁体   English

无法从 IntelliJ 中的 jar 文件导入 class

[英]Can't import class from jar file in IntelliJ

So I am trying to import this class from my jar file.所以我试图从我的 jar 文件中导入这个 class。 IntelliJ recognizes access to all the folder structures but not the class. IntelliJ 识别对所有文件夹结构的访问,但不识别 class。 在此处输入图像描述 Says: "Cannot resolve symbol 'Constants'.说:“无法解析符号‘常量’。

Note that I have tried clicking " Add library 'premiumdue.main.jar' to classpath " and it still doesn't work.请注意,我已尝试单击“将库‘premiumdue.main.jar’添加到类路径”,但它仍然不起作用。

I have no idea why it won't let me import the class.我不知道为什么它不允许我导入 class。

Here is a minimal intellij project showing my issue: https://www.dropbox.com/s/xzvv2x1ca2lld26/jar_issues.zip?dl=0这是一个显示我的问题的最小 intellij 项目: https://www.dropbox.com/s/xzvv2x1ca2lld26/jar_issues.zip?dl=0

For your sample Gradle project, the dependency jar has to be referenced in build.gradle file as described in this answer .对于您的示例 Gradle 项目,必须在build.gradle文件中引用依赖项 jar,如本答案中所述。

dependencies {
    implementation files('../create_jar.jar')
}

Proof:证明:

证明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM