安装 (startup.bat) 脚本无法启动我的应用程序,出现错误
Installation (startup.bat) script won't start my app, error appears
我正在尝试创建将启动我的 Java 应用程序的 .bat 脚本。应用程序使用了很多依赖项,所以我必须创建一个 fat 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 文件。一个 'normal' 罐子和一个胖子罐子。我使用了那个 fat 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 似乎存在一些问题:META-INF/spring.factories 中未找到自动配置 类。
我已经尝试 google 这个,但我找不到任何有用的东西,而且我已经在这上面花了太多时间,所以我别无选择。我希望有人知道如何从命令提示符启动应用程序。
当我从 Eclipse 启动应用程序时,一切正常。仅当我使用 .bat 脚本时才会出现此错误。
谢谢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>
我正在尝试创建将启动我的 Java 应用程序的 .bat 脚本。应用程序使用了很多依赖项,所以我必须创建一个 fat 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 文件。一个 'normal' 罐子和一个胖子罐子。我使用了那个 fat 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 似乎存在一些问题:META-INF/spring.factories 中未找到自动配置 类。
我已经尝试 google 这个,但我找不到任何有用的东西,而且我已经在这上面花了太多时间,所以我别无选择。我希望有人知道如何从命令提示符启动应用程序。
当我从 Eclipse 启动应用程序时,一切正常。仅当我使用 .bat 脚本时才会出现此错误。
谢谢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>