0

I'm using Intellij with Maven. I created a java program with an API interface. When I add it to maven, it seems to work because it even recommends me the Java API classes, but when I try to compile it, it says my package doesn't exists.

package htt.layeredstructures does not exist

Intellij recommends me using the class I imported from my .jar

Am I missing something?

The process I did was the following one:

  1. File
  2. Project Structure
  3. Modules
  4. Dependencies
  5. add
  6. JARs or directories
  7. Clicked the jar file and ok.

How it looks like

I also added it to my pom.xml like this:

        <dependency>
            <groupId>htt</groupId>
            <artifactId>LayeredStructures</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>

And it matches with the pom.xml of the provider program (the API one)

    <groupId>htt</groupId>
    <artifactId>LayeredStructures</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
  • You don't need to manually add dependencies to the IDEA project structure. Just click "Reload all maven projects" when you edit your pom. Have you run `mvn install` on your dependency project, to install that jar in your local maven repository? Incidentally, why are you using `provided` scope? – tgdavies Jul 23 '23 at 21:51
  • I did not run mvn install in my dependency project because I'm programming on windows and using IDEA integrated maven so I don't even have installed maven and don't have a local repository, so I tought I needed to add it to IDEA – Alberto Plaza Montes Jul 24 '23 at 07:09
  • You can run maven targets from IDEA. Run `install` for your dependency. Then IDEA should find it for your other project. – tgdavies Jul 24 '23 at 08:17
  • See also https://stackoverflow.com/a/22300875/12844632 on how to correctly add your own dependency to the Maven based project – Egor Klepikov Jul 24 '23 at 08:55
  • Thanks you very much @tgdavies I didn't know about the IDEA targets. It works correctly! – Alberto Plaza Montes Jul 27 '23 at 11:23

0 Answers0