1

I have created 2 dummy projects by start.spring.io (Maven, Java):

  1. com.example.lion
  2. com.example.zoo

I want to import lion project to zoo project as dependency.

So I go to lion folder and execute:

mvn clean install

mvn install:install-file -Dfile=target/lion-0.0.1-SNAPSHOT.pom -DpomFile=pom.xml

Then I add dependency to zoo pom.xml:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>lion</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

After that I execute mvn clean install in zoo folder.

I never got errors in console.

So now if I go to any class in zoo project, and import:

import com.example.lion.*;

Then mvn clean install, I get error:

package com.example.lion does not exist

In my IntelliJ IDEA I can see, that lion dependency is in External Libraries and maven-tool, but why I can not access that from code?

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • Does the maven project `com.example.lion` actually have a java package in `com.example.lion`? By this i mean does your `src` directory for the lion project have the children `main/java/com/example/lion`? – cheemcheem Apr 09 '19 at 13:38
  • Additionally the maven install line reads like you are putting a pom-file into the repo and not the jar file. – DrHopfen Apr 09 '19 at 13:42
  • Because if that directory doesn't exist then there would not be a package called `com.example.lion` to import in the zoo project. – cheemcheem Apr 09 '19 at 13:46
  • You don't have to and _should not_ perform `mvn install:install-file ...` explicitely in addition to `mvn install`! The `install` phase (invoked with the former executed) has the [Install Plugin's `install` goal](https://maven.apache.org/plugins/maven-install-plugin/install-mojo.html) bound to it by default which does this automatically for you, by using the project's POM declarations of the [Maven Coordinates](http://maven.apache.org/pom.html#Maven_Coordinates) ``, ``, `` (GAV). – Gerold Broser Apr 09 '19 at 13:59
  • cheemcheem: yes it exists. start.spring.io create all structure automatically DrHopfen: what would be correct install line? Gerold Broser: i tried only with `mvn install` now, but the problem is not solved – Nikolaj Sobolev Apr 09 '19 at 14:01
  • @NikolajSobolev Yes, this was just a hint for proper usage of Maven and such unrelated to your error. Sorry for not mentioning, but due to the 600 characters limit in comments... – Gerold Broser Apr 09 '19 at 14:05
  • @Gerold Broser you are looking like maven expert. pls help me guy :D, try the same, what I did in header. just create 2 projects on start.spring.io and add one to other as dependency. me noob has something forgot – Nikolaj Sobolev Apr 09 '19 at 14:14
  • @NikolajSobolev I tried it in Eclipse 2019-03. `import com.example.lion.*;` and `new LionApplication();` in `ZooApplication.main()` works there. – Gerold Broser Apr 09 '19 at 14:43
  • @Gerold Broser can you please push your code to github, and sent me all mvn commands that u have used. thx man! – Nikolaj Sobolev Apr 09 '19 at 15:00
  • @NikolajSobolev I did nothing else but what you describe: 1) Create the two projects on https://start.spring.io/. 2) Import them into Eclipse. 3) `lion $ mvn install` 4) add the dependency and the two lines of code to `zoo`. 5) `zoo $ mvn install`. Did you see [this answer](https://stackoverflow.com/a/16099592/1744774) already? – Gerold Broser Apr 09 '19 at 15:16
  • @NikolajSobolev I can reproduce your issue on the command line. I'm not an expert for spring boot but if you look inside the lion.jar the structure seems odd to me. The com.example.lion package is not located directly in the jar but under: `.m2\repository\com\example\lion\0.0.1-SNAPSHOT\lion-0.0.1-SNAPSHOT.jar\BOOT-INF\classes\com\example\lion\` probably this is normal for a spring boot application, but if this is supposed to be some kind of lib maybe it should not be a spring boot application by itself. – DrHopfen Apr 09 '19 at 15:23
  • found solution: https://stackoverflow.com/questions/45479060/spring-boot-package-does-not-exist-error – Nikolaj Sobolev Apr 09 '19 at 16:09

0 Answers0