I'm trying to create .bat script that will start my Java application. Application uses a lot of the dependencies so I have to create a fat jar:
I did that by adding this dependency to my 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>
After that I executed maven clean install which created two jar files in my target folder. One 'normal' jar and one fat jar. I used path to that fat jar and I tried to run it via my script but I got error.
Bat Script:
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
And error that I'm getting:
Error Log from command prompt:
}{
"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 . . .
So as you can see, it seems there is some problem with the "java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories."
I've tried to google this but I couldn't find anything useful and I've already spent too much time on this so I'm out of options. I hope someone knows how can I start application from my command prompt.
When I start application from Eclipse, everything works fine. This error is present only when I use my .bat script.
CodePudding user response:
Thanks M. Deinum, that fixed my problem:
I had to replace maven-assembly-plugin with the:
<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>