I have a java application and a Spring Boot application. I want to MySpringBootApp.run() and MySpringBootApp.hereYouHaveSomeInfo(), so I want to call methods of the Spring Boot App but Spring Boot kind of processes my class and renames it, so I get a ClassNotFoundException in the other App.
Thanks for you help!
If I understand you correctly, you are building the executable version of the spring boot application.
This jar file cannot be used as a dependency.
You need to build the classical jar file without the dependencies and add this to your application's dependency list.
I suppose you build with maven. The target folder will contain two files:
a yourapp-<version>.jar and
a yourapp-<version>.jar.original which is substanially smaller.
The .jar File is not suitable for inclusion as a dependency. You need the .original file. I suggest, if you need both, that you setup a project creating the .original file as regular .jar target, without the spring-boot plugin. And you add another project, with the spring-boot plugin, that requires the "simple" .jar file as dependency and has the spring-boot plugin enabled.
Your second application will also list the "simple" jar file as a dependency, the fat jar can be delivered as usual.
Related
I am provided with fat JAR's. Now I want to build a spring boot REST webservice for each. The webservice needs to use the classes and libraries in the fat JAR. Unfortunately the JAR'S in the lib folder of the fat JAR are not used by either maven or the IDE out of the box.
The only working solution I found so far is to unzip the fat JAR and then add the libs folder to my project.
How do I use the fat JAR with my spring boot webservice?
First what are the dates jars?do they contain spring annotations? You could create a spring boot project as a wrapper and write your own rest controllers to interface with the fat jars. It's hard to provide you more direction without understanding what the fat jars are
After deploying my project in IDE, all ok. But when I make 'package' at Maven, and tried to execute 'war' archive at the console, I get this exception:
Unable to open nested entry
'WEB-INF/lib/spring-aspects-4.3.8.RELEASE.jar'. It has been compressed
and nested jar files must be stored without compression. Please check
the mechanism used to create your executable jar file
At Spring Boot 1.5.2 was all good.
Looks like spring-aspects-4.3.8.RELEASE.jar that inside WEB-INF/lib/ is not extracted after compilation and your application can't extract classes from *.jar when you executing app.
Use maven dependencies instead direct *.jar files or specified plugin that will extract classes from *.jar's and add them to your app.
If you can't find public repository that provide required dependencies then use this instruction to add your external JAR files into your local maven repository. Then just add such dependency and build app again.
Why after building spring boot app, it generates two jar or war files with .original extension? I use spring boot maven build plugin.
For example:
application.jar
application.jar.original
The answer is that you are using repackage goal in your spring-boot-maven-plugin.
So, What it does?
Maven first builds your project and packages your classes and resources into a WAR (${artifactId}.war) file.
Then, repackaging happens. In this goal, all the dependencies mentioned in the pom.xml are packaged inside a new WAR (${artifactId}.war) and the previously generated war is renamed to ${artifactId}.war.original.
I assume that you're using the spring boot maven build plugin. This behavior is documented here: https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html
Is there a way to include specific packages during a spring boot application build? I have used spring-boot-maven plugin.
I understand it's not very customary to have classes in the same project which we don't want in the build, but I want to check if this is possible at all?
Even if a spring-boot executable jar can be built using any other way (i.e. by not using the spring-boot-maven plugin) I'd be delighted to know.
My spring boot web app works when run it in eclipse but when I try to run as an executable jar it fails to register any of the beans.
The configuration is all annotated - there are no xml config files.
I used mvn clean compile and mvn package commands to generate the jar.
Has anyone had a similar problem or have any ideas?
Thanks
Executable jars can not include nested jars, so it is necessary to workaround that limitation. A common approach is to shade the jars (i.e. unpacking all jars, and then packing in to single jar).
Spring-boot takes a different approach that relies on a custom maven repackaging plugin and handling by the Spring Boot Loader module. It generally just works, but per the documentation:
The spring-boot-starter-parent POM includes configuration
to bind the repackage goal. If you are not using the parent POM you
will need to declare this configuration yourself. See the plugin
documentation for details.
More information:
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started-first-application-executable-jar
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#executable-jar
My guess is that you are are you either not using the spring-boot maven plugin, or are not using the spring-boot parent POM. If that's not the issue, then you will need to post more information.
I have now resolved the problem and the app is working as a standalone jar.
Turns out the project folder structure was wrong - such that most of the app was unreachable!