Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import classes, IntelliJ showing BOOT-INF prefix and it seems to be related

This is with Java and Maven - I am trying to import some classes from a project that I could either build on my machine to the local mvn repository or I can download it from company's external mvn repository already a packaged jar. I did notice when looking on IntelliJ at the left "project" pane when looking at "External Libraries" and expanding the library in question that there is a "BOOT-INF.classes" prefix to all the classes underneath the jar in question. It's also a springboot project if that helps, although I'm able to import all the springboot classes and all the other classes from external repository just fine.

(Inside of IntelliJ Project View in Left Pane under "External Libraries")

Maven: org.springframework.boot:spring-boot-starter-test:2.0.0.RELEASE

Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.8.1

---jackson-core-2.8.1.jar

------com.faster.xml.jackson.core

------com.faster.xml.jackson.core.async

........(More packages listed)

Maven: com.mycompany.my.project:component-two-1.0.0-SNAPSHOT

Maven: com.mycompany.my.project:component-three-1.0.0-SNAPSHOT

---com.mycompany.my.project:component-1.0.0-20181201.jar

------BOOT-INF.classes

------BOOT-INF.classes.com.mycompany.project.my.package.one

---------MyClassOne

---------MyClassTwo

------BOOT-INF.classes.com.mycompany.project.my.package.one

------BOOT-INF.classes.com.mycompany.project.my.package.one.alpha

------BOOT-INF.classes.com.mycompany.project.my.package.one.bravo

like image 565
uh_big_mike_boi Avatar asked Dec 08 '18 03:12

uh_big_mike_boi


People also ask

What is boot INF folder?

BOOT-INF : Spring Boot applications load from the BOOT-INF folder. Therefore the application classes must be placed in a nested BOOT-INF/classes directory. Dependencies should be placed in a nested BOOT-INF/lib directory.


1 Answers

It sounds like you are trying to use a Spring Boot application as a dependency. Generally speaking this isn’t recommended as, like a war file, a Spring Boot application is not intended to be used as a dependency.

The Spring Boot documentation says the following:

If your application contains classes that you want to share with other projects, the recommended approach is to move that code into a separate module. The separate module can then be depended upon by your application and other projects.

If that’s not an option then you’ll need to configure your project to build both the application jar and one that is suitable for use as a dependency. From the same section of the documentation:

If you cannot rearrange your code as recommended above, Spring Boot’s Maven and Gradle plugins must be configured to produce a separate artifact that is suitable for use as a dependency. The executable archive cannot be used as a dependency as the executable jar format packages application classes in BOOT-INF/classes. This means that they cannot be found when the executable jar is used as a dependency.

To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified. This classifier is applied to the name of the executable archive, leaving the default archive for use as a dependency.

You’re using Maven so the appropriate configuration would look something like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <classifier>exec</classifier>
            </configuration>
        </plugin>
    </plugins>
</build>

If you were using Gradle, the appropriate configuration would look something like this:

jar {
    enabled = true
}

bootJar {
    classifier = 'exec'
}

With either build system, your application’s executable fat jar will now be published with an exec classifier. The normal jar that can be used as a dependency will be unclassified.

like image 180
Andy Wilkinson Avatar answered Sep 23 '22 12:09

Andy Wilkinson