简体   繁体   English

复制Spring启动应用程序中的依赖项

[英]copy dependencies in a spring boot application

I have spring boot application where during maven install, I want it to create a jar and copy the dependencies into a lib folder. 我有spring boot应用程序,在maven安装期间,我希望它创建一个jar并将依赖项复制到lib文件夹中。 I am trying to use these two maven plugins that are working fine in other maven projects but doesn't work in a spring boot application. 我正在尝试使用这两个maven插件,这些插件在其他maven项目中工作正常,但在spring引导应用程序中不起作用。

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

What is happening is that the jar gets created even if the maven-jar-plugin is omitted. 发生的事情是,即使省略了maven-jar-plugin,jar也会被创建。 And it doesn't do anything with the maven-dependency-plugin. 并且它对maven-dependency-plugin没有任何作用。 So it pretty much ignores both these plugins. 所以它几乎忽略了这两个插件。

I put the Spring Boot plugin after copy-dependencies and work fine! 我把Spring Boot插件放在copy-dependencies之后,工作正常!

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

Notes: I clean Maven repository to work! 注意:我清理Maven存储库工作!

I think you should try Spring boot + Gradle: Spring boot Gradle 我想你应该尝试Spring boot + Gradle: Spring boot Gradle

In build.gradle file, you can customize the build process and copy your dependencies into lib folder by using gradle copy method. 在build.gradle文件中,您可以使用gradle copy方法自定义构建过程并将依赖项复制到lib文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 spring 引导应用程序如何受 maven 依赖项影响? - How is the spring boot application affected by the maven dependencies? Spring Boot Gradle Java 应用程序中的 SQL Server 依赖项 - SQL Server dependencies in Spring Boot Gradle Java application spring-boot maven rest 应用程序需要哪些依赖项? - Which dependencies are required for a spring-boot maven rest application? 应用上下文中一些bean的依赖形成了一个循环:在spring boot - The dependencies of some of the beans in the application context form a cycle: in spring boot 如何在Spring Boot应用程序中模拟外部依赖关系? - How do you mock external dependencies in spring boot application? Spring boot 应用上下文中一些bean的依赖形成了一个循环: - Spring boot The dependencies of some of the beans in the application context form a cycle: Spring Boot 1.5.1和“应用程序上下文中某些Bean的依赖性形成一个循环” - Spring Boot 1.5.1 and “The dependencies of some of the beans in the application context form a cycle” 应用上下文中一些bean的依赖在spring boot中形成循环错误 - The dependencies of some of the beans in the application context form a cycle errors in spring boot Spring Boot包含传递依赖项 - Spring boot include transitive dependencies Spring Boot 中的 Maven 依赖问题 - Maven dependencies issues in Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM