I created an local Maven Repo and deploy a own lib there: with:
mvn clean package install deploy
on:
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>de.example</groupId>
<artifactId>example-lib</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>example-lib</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>example.repo</id>
<name>example internal mvn repository</name>
<url>file://${project.basedir}/../mvn-repo</url>
</repository>
</distributionManagement>
Now Another project consumes it with:
<repositories>
<repository>
<id>example.repo</id>
<url>file://${project.basedir}/../mvn-repo</url>
</repository>
</repositories>
...
<dependency>
<groupId>de.example</groupId>
<artifactId>example-lib</artifactId>
<version>0.0.1</version>
</dependency>
...
but upon compiling the project all symbols are missing from the lib (but the dependency IS resolved, and the .jar file is there)
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/CoreApplication.java:[11,31] package de.example.examplelib does not exist
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/DbExampleService.java:[11,42] package de.example.examplelib.db.example does not exist
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/DbExampleService.java:[12,42] package de.example.examplelib.db.example does not exist
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/DbExampleService.java:[19,17] cannot find symbol
symbol: class UserRepository
location: class de.example.core.DbExampleService
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/DbExampleService.java:[35,39] cannot find symbol
symbol: class User
location: class de.example.core.DbExampleService
I have searched for the last 4 hours, maybe I just miss a little basic thing?? Open for hints. Thanks in advance.
When Maven cannot find a dependency, it explicitly says so. Your problem is of a different nature; it appears that your jar might be actually empty (i.e. you have the right dependency; it just isn't packaged right).
Maven repository is just a simple collection of files; you can just go in it and open up your jar; I suggest to check your mvn-repo to see if the jar you're including contains the classes you expect to contain.
In case I'm right (i.e. your jar isn't packaged right) look at the default maven directory structure etc (Maven is used to pick up java
files by default from src/main/java
; perhaps you use a different source folder and you're not telling this to Maven?)
Edit 1 Summing up the discussion in the comments and other answer :
So far, we know that your jar is packaged incorrectly. Well, it is packaged incorrectly for the purpose of being consumed by other projects. Therefore, the error that you're seeing is normal. Punctually, the error is because you're referring to the class
de/example/examplelib/db/example/User.class
for example, but this class is located in the wrong place (the de
package should be in the root of the jar and not in the BOOT-INF/classes
folder).
Most likely, this happens because the pom.xml
file that you're using to package your library is inheriting from a spring-boot parent (or you have some other config in it that you haven't shown).
Therefore, in the light of these things, you need to re-state your problem: