Home > Mobile >  Don't find any classes in own maven Library
Don't find any classes in own maven Library

Time:07-12

I created a new Maven project, that I want to use as a library in another project. The library compiles and loaded into our own Maven repository. In my other project, I insert the dependency. The dependency is found, but in the project I can't use any class of the library.

The external libraries browser shows the dependency. I can look into the classes. All there, but on compile the package isn't found.

What am I doing wrong?

POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>de.myown.defaultplugin</groupId>
    <artifactId>DefaultPlugIn</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>DefaultPlugIn</name>
    <description>DefaultPlugIn</description>
    <properties>
        <java.version>13</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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>

</project>

Interface:

package de.myown.defaultplugin.defaultplugin;

import java.util.HashMap;
import java.util.Map;

public interface DefaultPlugin {
    public String name = "";
    public String description = "";
    public Map<String, String> dependencies = new HashMap<>();
    public static void main(String[] args) {
    }
}

Class:

package de.myown.defaultplugin.defaultplugin;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
public class DefaultPlugInApplication implements DefaultPlugin {

    public String name = "Empty Plugin";
    public String description = "Not yet described";
    public Map<String, String> dependencies = (Map<String, String>) new HashMap<>().put("Database","1.0.0");

    public static void main(String[] args) {
        SpringApplication.run(DefaultPlugInApplication.class, args);
        System.err.println("In the Plugin");
    }

}

Dependency in project:

<dependency>
    <groupId>de.myown.defaultplugin</groupId>
    <artifactId>DefaultPlugIn</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

Project compilation error:

java: package de.myown.defaultplugin.defaultplugin does not exist

EDIT: I create a new project, without SpringBoot. Only Quickstart Archetype and copy the interface into it. From there I can import the interface without any problems. Why this don't work with SpringBoot?

EDIT2: I found this https://medium.com/xebia-france/import-spring-boot-application-as-a-maven-dependency-a25e03e5c3a I tested it, and it generate me an third Jar file. This I can import and all works. But the filesize is only 5kb. And the shade plugin not work. I think that can be a problem, what do you think?

CodePudding user response:

Here is the official answer. After a long way of search:

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.build.use-a-spring-boot-application-as-dependency

It is not possible

  • Related