IDEA 编译打包执行jar包报错

IDEA 编译打包执行jar包报错

在IDEA运行项目没有问题,打包成 jar 包运行出错
错误信息:

F:\MyProject\DIYC\diyc_register\target>java -jar diyc_register-1.0.0.1-jar-with-dependencies.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::

2019-11-20 09:45:25.241  INFO 23028 --- [           main] com.dingfeng.EurekaServerApplication     : Starting EurekaServ
erApplication on PC-20161218SQLW with PID 23028 (F:\MyProject\DIYC\diyc_register\target\diyc_register-1.0.0.1-jar-with-d
ependencies.jar started by Administrator in F:\MyProject\DIYC\diyc_register\target)
2019-11-20 09:45:25.244  INFO 23028 --- [           main] com.dingfeng.EurekaServerApplication     : No active profile s
et, falling back to default profiles: default
2019-11-20 09:45:25.280  INFO 23028 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.spri
ngframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@20d525: startup date [Wed Nov 20
 09:45:25 CST 2019]; root of context hierarchy
2019-11-20 09:45:25.374 ERROR 23028 --- [           main] o.s.boot.SpringApplication               : Application run fai
led

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.
        at org.springframework.util.Assert.notEmpty(Assert.java:450) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:n
a]
        at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigu
rationImportSelector.java:160) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportS
elector.java:96) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoCon
figurationImportSelector.java:386) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(Con
figurationClassParser.java:828) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationC
lassParser.java:563) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188) ~[di
yc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(Configura
tionClassPostProcessor.java:316) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(Conf
igurationClassPostProcessor.java:233) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcess
ors(PostProcessorRegistrationDelegate.java:271) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostPro
cessorRegistrationDelegate.java:91) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplic
ationContext.java:692) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:530) ~
[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerAppli
cationContext.java:140) ~[diyc_register-1.0.0.1-jar-with-dependencies.jar:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [diyc_register-1.0.0.1-jar-wit
h-dependencies.jar:na]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [diyc_register-1.0.0.1-
jar-with-dependencies.jar:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [diyc_register-1.0.0.1-jar-with-de
pendencies.jar:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [diyc_register-1.0.0.1-jar-with-d
ependencies.jar:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [diyc_register-1.0.0.1-jar-with-d
ependencies.jar:na]
        at com.dingfeng.EurekaServerApplication.main(EurekaServerApplication.java:12) [diyc_register-1.0.0.1-jar-with-de
pendencies.jar:na]

2019-11-20 09:45:25.413  INFO 23028 --- [           main] ConfigServletWebServerApplicationContext : Closing org.springf
ramework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@20d525: startup date [Wed Nov 20 09
:45:25 CST 2019]; root of context hierarchy

F:\MyProject\DIYC\diyc_register\target>

解决方案:
修改 pom.xml

<!-- 编译插件 -->
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <fork>true</fork>
        <!--suppress UnresolvedMavenProperty -->
        <mainClass>${start-class}</mainClass>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-5</version>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>com.dingfeng.EurekaServerApplication</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>assemble-all</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

执行命令:

mvn clean package -Dmaven.test.skip=ture  //执行打包并忽略测试文档编译

最后会在 target 目录下生成 三个文件:
XXX-1.0.0.1.jar
XXX-1.0.0.1.jar.original
XXX-1.0.0.1-jar-with-dependencies.jar
只要执行 java -jar XXX-1.0.0.1.jar 就可以了

参考:http://www.it1352.com/907745.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值