0

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.

Gregor Sklorz
  • 1,645
  • 2
  • 19
  • 27
  • new findings: on: 'mvn jar:jar' I get waring: '[WARNING] JAR will be empty - no content was marked for inclusion!' But I have no idea how to mark something for inclusion? – Gregor Sklorz Jun 08 '17 at 18:04
  • First you are calling `mvn clean package install deploy` which means you are running serveral things several times. Only a simple `mvn clean deploy` is sufficient. Furthermore you have configured something like this in your second project: `...file://...` this is not needed. If you have made an `mvn install` everything is stored in your local repository and from there you can consume it without supplemental configuration of repositories...use the defaults.. – khmarbaise Jun 08 '17 at 18:05
  • @khmarbaise Your rigth, I called it multiple times cause frusttration and to show that I tried diffrent calls. The [file://] thing is for later infrastructure to share it with colleagues without pushing it online or to artifactory. But thanks for your feedback! – Gregor Sklorz Jun 08 '17 at 18:34

1 Answers1

0

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:

  • Do you want your library-jar to be a spring-boot executable jar? If yes, then I can't help you because I don't know very much spring-boot, and I don't know if you can have a spring-boot jar which is both executable and library. If no, then you need to remove spring-boot as a parent and re-package it.
  • Did you intended your second project to be a spring-boot executable? If yes, then you need to add the parent that you have in your lib project.
Andrei
  • 1,613
  • 3
  • 16
  • 36
  • Sounds good... I checked the jars, they are fine, but it still fails. – Gregor Sklorz Jun 08 '17 at 18:30
  • **Oh My! Thank you so much!** It seems so obvious now. I just removed the parent in pom, the main start class and the tests (runned by spring boot). And it works as it should. ... This BOOT-INF was so obvious to me that I didnt questioned it. Thanks again. – Gregor Sklorz Jun 09 '17 at 09:16