安装(startup.bat)脚本不会启动我的应用程序,出现错误
Posted
技术标签:
【中文标题】安装(startup.bat)脚本不会启动我的应用程序,出现错误【英文标题】:Installation (startup.bat) script won't start my app, error appears 【发布时间】:2021-12-31 22:43:29 【问题描述】:我正在尝试创建将启动我的 Java 应用程序的 .bat 脚本。应用程序使用了很多依赖项,所以我必须创建一个胖 jar:
我通过将此依赖项添加到我的 pom.xml 来做到这一点:
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>my.path.MicroserviceApp</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
之后我执行了 maven clean install,它在我的目标文件夹中创建了两个 jar 文件。一个“普通”罐子和一个肥罐子。我使用了那个胖 jar 的路径,我试图通过我的脚本运行它,但我得到了错误。
蝙蝠脚本:
echo off
set "JAVA_HOME=C:/Program Files/Java/jdk1.8.0_291"
set "PATH=C:/Program Files/Java/jdk1.8.0_291/bin;%PATH%"
set "MICRO_HTTP=C:/Users/just.quest/workspace/application_parent/MicroserviceApp"
set "CLASSPATH=%MICRO_HTTP%/target/MicroserviceApp-20.14.1-1-jar-with-dependencies.jar"
java -jar %CLASSPATH%
pause
我得到的错误:
来自命令提示符的错误日志:
"timestamp" : "2021-11-22T09:40:52.563Z",
"level" : "ERROR",
"thread" : "main",
"logger" : "org.springframework.boot.SpringApplication",
"message" : "Application run failed",
"context" : "default",
"exception" : "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.\r\n\tat org.springframework.util.Assert.notEmpty(Assert.java:470)\r\n\tat org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:180)\r\n\tat org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:123)\r\n\tat org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:434)\r\n\tat org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:879)\r\n\tat org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:809)\r\n\tat org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:780)\r\n\tat org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:193)\r\n\tat org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)\r\n\tat org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247)\r\n\tat org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311)\r\n\tat org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112)\r\n\tat org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746)\r\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)\r\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)\r\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)\r\n\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:338)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)"
"timestamp" : "2021-11-22T09:40:52.565Z",
"level" : "DEBUG",
"thread" : "main",
"logger" : "org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext",
"message" : "Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6fa51cd4, started on Mon Nov 22 10:40:52 CET 2021",
"context" : "default"
Press any key to continue . . .
如您所见,“java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories.”似乎有一些问题。
我试过用谷歌搜索,但找不到任何有用的东西,而且我已经花了太多时间在这上面,所以我别无选择。我希望有人知道如何从命令提示符启动应用程序。
当我从 Eclipse 启动应用程序时,一切正常。仅当我使用 .bat 脚本时才会出现此错误。
【问题讨论】:
放弃组装插件,添加spring-boot-maven-plugin
已经创建了一个胖的可运行 jar。您正在解决/反对框架而不是使用它。
【参考方案1】:
谢谢M。 Deinum,解决了我的问题:
我不得不将 maven-assembly-plugin 替换为:
<build>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
</build>
【讨论】:
以上是关于安装(startup.bat)脚本不会启动我的应用程序,出现错误的主要内容,如果未能解决你的问题,请参考以下文章
tomcat启动不成功(点击startup.bat闪退)的解决办法
startup.bat脚本启动tomcat时,cmd命令窗口闪现问题及Neither the JAVA_HOME nor the JRE_HOME environment variable is de