How to create executable jar file from springboot - maven application? - spring-boot

When I tried to create a jar file using maven plugin in eclipse, I got thus error while trying to execute that jar:
Exception in thread "main" java.lang.IllegalStateException: Failed to
get nested archive for entry
BOOT-INF/lib/spring-boot-starter-actuator-2.0.3.RELEASE.jar
This seems to be a bug in 2017. Is there any solution for this now?

Your executable jar file doesn't contain above jar file.You should build jar with dependencies.
Right click project then click 'Run As'
Maven Build
And you should type 'package' in input area then run.
/path/your/project/target/ there is your .jar file with dependencies.

Related

when i convert my spring boot program as jar file and used thar jar file in another project i got error in repository

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.proretention.repository.LogRepository.save(Object)" because "this.logRepo" is null
at com.proretention.service.LogService.save(LogService.java:27)
at com.proretention.logger.LoggerTestApplication.main(LoggerTestApplication.java:20)
This probably happens because your jar file only contains the classes of your project. You have to create a 'fat jar' which is a jar that also contains the dependencies of your project. If you are using Gradle the output of the 'bootJar' task is what you are looking for.
The 'jar' task creates a plain jar with the following name inside build/libs: "PROJECTNAME-0.0.1-SNAPSHOT-plain.jar" while the 'bootJar' task creates one with this name "PROJECTNAME-0.0.1-SNAPSHOT.jar", this is the one you need.

Tomcat not starting after changing packaging from jar to war

Firstly, after changing the packaging from jar to war for spring boot application, I am not able to do maven build. Getting below error:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.goel.GameApplication]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/application.properties]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:189)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
The above error comes when maven tries to run app tests. So I commented out the test and ran maven build and I was able to get a war file.
But after deploying the same war file in tomcat(aws), I am getting the same error.
I have followed the 3 step approach properly.Ref: https://www.javadream.in/convert-jar-to-war-in-spring-boot/
I have checked that the build-path does not exclude resource or application.properties
I have tried moving from spring IDE to Eclipse IDE.
I have opened the war file and have verified that the application.properties file is present under WEB-INF/classes/application.properties.
I have read and tried many other things but nothing helped. Any pointers will be helpful. Thanks in advance.
Please do let me know if more info is required,
Java Version: 1.8 ,
Maven Version: 3.6.3 ,
spring-boot-starter-parent: 2.5.4
Exploded war file
Screenshot for SSGApplication

Springboot - Executing Fat Jar

I have a springboot application which creates a JAR artifact using maven build. I understand that we can execute this jar from command line by going into target folder and executing appropriate command but what I want to know that how can I export this jar to a different machine(Unix Box) and execute the jar?

ClassNotFoundException in spring project with maven

I have created a spring project with maven and it works fine. I am trying to add a jar file to the project, eclipse does not give any errors but when i start the server and try to access to the page which uses a class from that jar file i get a classNotFound exception.
My steps are..
1 - I put the jar file in src->main->resources
2 - I added it to build path by right clicking and saying add to build path.
3 - I add the project to tomcat and start the server
The thing is i looked at the tomcat deployment directory and the .jar file appears in classes directory. When i take copy the file from classes to lib (which has libraries downloaded by maven) project works fine.

What's "grails package" actually do?

I'd like to debug packing my grails project into war file by 'grails war' (because of an error described here: Can not build war from grails project) so I'm looking for differences in (ant?) commands which are executed step by step by 'grails package' (which my project does successfully) and 'grails war' in it's packaging section (which ends up with error: Error WAR packaging error: startup failed ).

Resources