【问题标题】:copy dependencies in a spring boot application在 Spring Boot 应用程序中复制依赖项
【发布时间】:2016-05-10 16:19:10
【问题描述】:

我有 spring boot 应用程序,在 maven 安装期间,我希望它创建一个 jar 并将依赖项复制到 lib 文件夹中。我正在尝试使用这两个在其他 maven 项目中运行良好但在 Spring Boot 应用程序中不起作用的 maven 插件。

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
           <useDefaultManifestFile>true</useDefaultManifestFile>
           <archive>
              <manifest>
                 <addClasspath>true</addClasspath>
                 <mainClass>xxx.Main</mainClass>
                 <classpathPrefix>lib/</classpathPrefix>
              </manifest>
           </archive>
        </configuration>
     </plugin>
     <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
           <execution>
              <phase>install</phase>
              <goals>
                 <goal>copy-dependencies</goal>
              </goals>
              <configuration>
                 <outputDirectory>${project.build.directory}/lib</outputDirectory>
              </configuration>
           </execution>
        </executions>
     </plugin>

发生的情况是,即使省略了 maven-jar-plugin,也会创建 jar。它对 maven-dependency-plugin 没有任何作用。所以它几乎忽略了这两个插件。

【问题讨论】:

  • @Anton:我没见过。似乎这就是我想要的。我会试试看。谢谢!
  • 好的,我试过了。它仍然没有告诉我如何将依赖项复制到外部文件夹。
  • 为什么要将依赖项放到外部文件夹中?!你的 jar 应该包含所有你需要的东西,这样你就不需要弄乱额外的文件夹了。
  • 还有其他团队构建的其他应用,共享很多这些常用的jar(Hibernate、spring等)。如果我将它们放在外部文件夹中,则可以选择在将来共享这些依赖项。

标签: java spring maven spring-boot


【解决方案1】:

我将 Spring Boot 插件放在复制依赖项之后并且工作正常!

<plugin>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

注意:我清理了 Maven 存储库以工作!

【讨论】:

    【解决方案2】:

    我认为你应该试试 Spring boot + Gradle: Spring boot Gradle

    在 build.gradle 文件中,您可以自定义构建过程,并使用 gradle 复制方法将依赖项复制到 lib 文件夹中。

    【讨论】:

      猜你喜欢
      • 2018-10-07
      • 2017-04-09
      • 1970-01-01
      • 2023-03-10
      • 2018-05-07
      • 2021-01-01
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      相关资源
      最近更新 更多