Search code examples
javaintellij-ideaimportjarimporterror

Can't import class from jar file in IntelliJ


So I am trying to import this class from my jar file. IntelliJ recognizes access to all the folder structures but not the class. enter image description here Says: "Cannot resolve symbol 'Constants'.

Note that I have tried clicking "Add library 'premiumdue.main.jar' to classpath" and it still doesn't work.

I have no idea why it won't let me import the class.

Here is a minimal intellij project showing my issue: https://www.dropbox.com/s/xzvv2x1ca2lld26/jar_issues.zip?dl=0


Solution

  • For your sample Gradle project, the dependency jar has to be referenced in build.gradle file as described in this answer.

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

    Proof:

    proof