spring-boot-maven-plugin创建带依赖项的jar

时间:2017-07-17 10:38:19

标签: java maven spring-boot jar spring-boot-maven-plugin

我的项目在日食中运行良好。我使用以下插件来构建带有依赖项的jar。

<build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>com.project.App</mainClass>
                </manifest>
            </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
</build>

在运行jar时,我收到以下错误。

2017-07-17 15:21:06.825 ERROR 17587 --- [           
main] o.s.boot.SpringApplication               : 
Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: 
Failed to process import candidates for configuration class [com.project.App]; 
nested exception is java.lang.IllegalArgumentException: 
No auto configuration classes found in META-INF/spring.factories. 
If you are using a custom packaging, make sure that file is correct.

我发现this解决方案使用spring-boot-maven-plugin并修改了我的代码,如下所示。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
              <fork>true</fork>
              <mainClass>com.project.App</mainClass>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>repackage</goal>
                </goals>
              </execution>
            </executions>
        </plugin>
    </plugins>
</build>

错误已修复。但是,通过此过程创建的jar不包含依赖项。是否可以使用spring-boot-maven-plugin构建具有依赖关系的jar?请提出解决方案。

0 个答案:

没有答案