<i id='lw46p'><tr id='lw46p'><dt id='lw46p'><q id='lw46p'><span id='lw46p'><b id='lw46p'><form id='lw46p'><ins id='lw46p'></ins><ul id='lw46p'></ul><sub id='lw46p'></sub></form><legend id='lw46p'></legend><bdo id='lw46p'><pre id='lw46p'><center id='lw46p'></center></pre></bdo></b><th id='lw46p'></th></span></q></dt></tr></i><div id='lw46p'><tfoot id='lw46p'></tfoot><dl id='lw46p'><fieldset id='lw46p'></fieldset></dl></div>
    <bdo id='lw46p'></bdo><ul id='lw46p'></ul>
  • <small id='lw46p'></small><noframes id='lw46p'>

      <tfoot id='lw46p'></tfoot>
      <legend id='lw46p'><style id='lw46p'><dir id='lw46p'><q id='lw46p'></q></dir></style></legend>

      1. 无法导入类,IntelliJ 显示 BOOT-INF 前缀,似乎相关

        时间:2023-09-27
          <bdo id='Xd2vG'></bdo><ul id='Xd2vG'></ul>

          <i id='Xd2vG'><tr id='Xd2vG'><dt id='Xd2vG'><q id='Xd2vG'><span id='Xd2vG'><b id='Xd2vG'><form id='Xd2vG'><ins id='Xd2vG'></ins><ul id='Xd2vG'></ul><sub id='Xd2vG'></sub></form><legend id='Xd2vG'></legend><bdo id='Xd2vG'><pre id='Xd2vG'><center id='Xd2vG'></center></pre></bdo></b><th id='Xd2vG'></th></span></q></dt></tr></i><div id='Xd2vG'><tfoot id='Xd2vG'></tfoot><dl id='Xd2vG'><fieldset id='Xd2vG'></fieldset></dl></div>

            <legend id='Xd2vG'><style id='Xd2vG'><dir id='Xd2vG'><q id='Xd2vG'></q></dir></style></legend>

              • <small id='Xd2vG'></small><noframes id='Xd2vG'>

                  <tbody id='Xd2vG'></tbody>
                • <tfoot id='Xd2vG'></tfoot>
                  本文介绍了无法导入类,IntelliJ 显示 BOOT-INF 前缀,似乎相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

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

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

                  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

                  ........(列出更多包)

                  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

                  解决方案

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

                  Spring Boot 文档 说明如下:

                  <块引用>

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

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

                  <块引用>

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

                  <块引用>

                  要生成两个工件,一个可以用作依赖项,另一个是可执行的,必须指定一个分类器.此分类器应用于可执行存档的名称,将默认存档用作依赖项.

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

                  <build><插件><插件><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><配置><分类器>执行器</分类器></配置></插件></插件></构建>

                  如果您使用的是 Gradle,则适当的配置应如下所示:

                  jar {启用 = 真}引导罐{分类器 = '执行'}

                  使用任一构建系统,您的应用程序的可执行 fat jar 现在将使用 exec 分类器发布.可以用作依赖的普通jar将是未分类的.

                  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

                  解决方案

                  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.

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

                  上一篇:为什么导入 javax.swing.* 而不是 java.swing.* 下一篇:如果 java Hello World 程序在包中,为什么我不能运

                  相关文章

                  最新文章

                  1. <tfoot id='PnHIj'></tfoot>

                    <small id='PnHIj'></small><noframes id='PnHIj'>

                    <legend id='PnHIj'><style id='PnHIj'><dir id='PnHIj'><q id='PnHIj'></q></dir></style></legend>
                    1. <i id='PnHIj'><tr id='PnHIj'><dt id='PnHIj'><q id='PnHIj'><span id='PnHIj'><b id='PnHIj'><form id='PnHIj'><ins id='PnHIj'></ins><ul id='PnHIj'></ul><sub id='PnHIj'></sub></form><legend id='PnHIj'></legend><bdo id='PnHIj'><pre id='PnHIj'><center id='PnHIj'></center></pre></bdo></b><th id='PnHIj'></th></span></q></dt></tr></i><div id='PnHIj'><tfoot id='PnHIj'></tfoot><dl id='PnHIj'><fieldset id='PnHIj'></fieldset></dl></div>

                      • <bdo id='PnHIj'></bdo><ul id='PnHIj'></ul>