0
votes


I need help. I have 2 spring-boot-jar project maven base I want to import first one into the second one like in the picture

enter image description here

I import the Util Jar as a blow in Config Spring-Boot and Run Spring Boot But It's Show error

<dependency>
    <groupId>com.ballistic</groupId>
    <artifactId>adminutil</artifactId>
    <version>0.1</version>
</dependency>

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project config: Compilation failure: Compilation failure:


Pom.xm Util-Jar

<?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 http://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.1.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.ballistic</groupId>
<artifactId>adminutil</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>adminutil</name>

<description>
    Util For Admin Tool Help In All Jar's
</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Add Log4j2 Dependency -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>

    <!-- Needed for Async Logging with Log4j 2 -->
    <dependency>
        <groupId>com.lmax</groupId>
        <artifactId>disruptor</artifactId>
        <version>3.4.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
    </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>

Pom.xm Config Jar

<?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 http://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.1.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.ballistic</groupId>
<artifactId>config</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>config</name>

<!--
 mvn install:install-file -Dfile=C:\Users\AdMaxim\Desktop\App\adminutil\target\adminutil-0.1.jar -DgroupId=com.ballistic -DartifactId=adminutil -Dversion=0.1 -Dpackaging=jar
 -->
<description>
    Config Help The Configuration Of All Sub Jar
</description>

<properties>
    <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-mongodb</artifactId>
    </dependency>

    <dependency>
        <groupId>com.ballistic</groupId>
        <artifactId>adminutil</artifactId>
        <version>0.1</version>
    </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>
            <configuration>
                <includeSystemScope>true</includeSystemScope>
            </configuration>
        </plugin>
    </plugins>
</build>

1
post pom.xml of both projectuser4477122
Please show the compilation error ...which is lines above the message you have posted.khmarbaise
@ArunKumar check plz and the error is class not found which is in util jarNabeel Ahmed
You cannot use a Spring Boot jar as dependency in another jar due to the structure inside of the jar file. Also I highly doubt that the util project needs to be a seperate runnable Spring Boot application. So I would suggest/expect no spring-boot-maven-plugin in there. If you really want to keep it produce 2 resources one pacakged by Spring Boot the other a regular jar. See docs.spring.io/spring-boot/docs/2.1.3.RELEASE/reference/… to learn how to do that.M. Deinum
@M.Deinum Your comment help me on my project, i had the classifier exec on the imported project and now i can access to classes :)Dervillers Mattéo

1 Answers

0
votes

You have to use repackaging for this requirement.

By default, the repackage goal will replace the original artifact with the repackaged one. That's a sane behaviour for modules that represent an app but if your module is used as a dependency of another module, you need to provide a classifier for the repackaged one.

The reason for that is that application classes are packaged in BOOT-INF/classes so that the dependent module cannot load a repackaged jar's classes. If that is the case or if you prefer to keep the original artifact and attach the repackaged one with a different classifier, configure the plugin as follows:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>1.4.1.RELEASE</version>
    <executions>
      <execution>
        <goals>
          <goal>repackage</goal>
        </goals>
        <configuration>
          <classifier>exec</classifier>
        </configuration>
      </execution>
    </executions>
    ...
  </plugin>

or you can declare main class also.

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>YourMainClass.java</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>