Include specific packages in spring boot application build - java

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.

Related

How to include a jar without its subjar

I have a struts project. It has many jars in its APP-INF/lib directory and the packaged ear size is huge. I also have another spring boot project and it has one utility class.
My target is to use that utility from the struts project.
The problem here is, if I include this spring-boot jar in the pom.xml, it includes the spring boot jar with all its dependency which are already present in the struts project. This makes the ear more huge. The jars are copied twice in a way. Basically the project becomes like this:
struts-project
--APP-INF/libs/
----**.jar (many jars)
----spring-boot-project.jar
--------BOOT-CONF/libs/
-------------**.jar (again many jars, most of them already in one level above directory)
My end goal is to use the utility, for which I have 2 ways (what I have in mind, more ways possible)
Include the spring boot jar, but find a way to reduce packaged ear size.
Create a rest api in the spirng boot project just to use the jar. But if the service is down anyhow, it will have huge impact on main application - so don't want to use this way also.
Please suggest more ways to achieve my end goal. Or any improvement/suggestion in the above approaches.
In order to use utility / commons classes in many project you should create separate project for utility.
Utility project should not use any dependency or very little in other case you should redesign it.

Why does maven jar project not contain it's dependencies?

I have recently been working with Spring Boot and all of the jar dependencies are packaged within the Spring Boot 'uber' jar.
I have recently made a regular jar application and none of the jars are packaged within the jar, but I am still able to execute the code within the java by calling specific classes (with main methods)
Can anyone shed some light? Any similar questions I see regarding this always speak to the shade plugin
EDIT:
I understand I didn't specify the shade plugin to create an uber jar, but could anyone explain why it's not needed for the majority of projects, and how the code is able to run if the dependencies are not there?

To add External Spring jars for a spring project without Maven

I just downloaded the Spring IDE and Tool suite from Eclipse Market place.I am creating a sample Spring project using Spring core containers. I am following a tutorial video for that. I want to set build path by adding external downloaded Spring jars for that I have gone to build path of a specific project and I don't know where my downloaded external spring jars. I have searched in my local drive in java folder in programming files and also where my eclipse is saved. But I cannot find where my external spring jar files saved.
Kindly tell me the path where I can find external downloaded jars from eclipse Marketplace
Spring Suite tool is Rapid Application Development plugin, which helps to decrease spring configuration time and help you focus on core logic of your application.
Even though, As Martin Lippert Explain below, you might have to use Maven (Build Automation tool, And project dependency manager) for creating spring project.
people often use Maven for their dependency management (or Ivy or something else) and would like to use a specific version of the Spring framework (instead of the libs that are inside STS and used by STS itself). But you can define a user-defined Library that contains all the necessary Spring framework JARs and maybe others and just add that user-defined library to each project. Would make it a bit easier as adding several JARs all over again.
Maven uses a filesystem tree as a repository to store jar files with there metadata(dependency, version, etc.) which is located (by default) under your home or My Document Path within .m2 directory (folder).

Start Spring Boot App from other application

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.

Spring boot application can't see beans when run as a jar

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!

Categories