无法导入类,IntelliJ显示BOOT-INF前缀,似乎与之相关 [英] Can't import classes, IntelliJ showing BOOT-INF prefix and it seems to be related

查看:401
本文介绍了无法导入类,IntelliJ显示BOOT-INF前缀,似乎与之相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是与Java和Maven一起使用的-我正在尝试从一个项目中导入一些类,这些类可以在我的机器上构建到本地mvn存储库中,也可以从公司的外部mvn存储库中下载(已打包).当查看外部库"并展开相关库时,我在左侧项目"窗格中查看IntelliJ时确实注意到,有问题的jar下方的所有类都有一个"BOOT-INF.classes"前缀.如果有帮助的话,这也是一个springboot项目,尽管我可以从外部存储库中导入所有springboot类和所有其他类.

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.

(外部库"下左窗格的IntelliJ项目视图内部)

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

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

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

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

--- jackson-core-2.8.1.jar

---jackson-core-2.8.1.jar

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

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

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

------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-two-1.0.0-SNAPSHOT

Maven:com.mycompany.my.project:component-three-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

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

------ BOOT-INF.classes

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

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

---------- MyClassOne

---------MyClassOne

--------- MyClassTwo

---------MyClassTwo

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

------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.alpha

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

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

推荐答案

听起来您正在尝试使用Spring Boot应用程序作为依赖项.一般来说,不建议这样做,因为与war文件一样,Spring Boot应用程序也不希望用作依赖项.

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.

如果您的应用程序包含要与其他项目共享的类,则建议的方法是将该代码移到单独的模块中.然后,您的应用程序和其他项目可以依赖单独的模块.

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.

如果这不是一个选项,则需要配置您的项目以构建应用程序jar和一个适合用作依赖项的jar.在文档的同一部分:

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:

如果您不能按照上面的建议重新排列代码,则必须配置Spring Boot的Maven和Gradle插件以生成单独的工件,该工件适合用作依赖项.可执行存档不能用作依赖项,因为可执行jar格式将BOOT-INF/classes中的应用程序类打包.这意味着当将可执行jar用作依赖项时,找不到它们.

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.

您正在使用Maven,因此适当的配置应如下所示:

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>

您的应用程序的可执行文件胖子现在将使用exec分类器发布.可以用作依赖项的普通jar将不会被分类.

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.

这篇关于无法导入类,IntelliJ显示BOOT-INF前缀,似乎与之相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆