Sping Boot to generate jar with only class files and place dependency in a separate location - spring-boot

I would like to create jar's with only class files for my project and to copy all it's dependency into a separate folder and put these in docker.

You can copy all dependency into a separate folder using maven's copy-dependencies
Using maven configuration profile and exec tag's you can create jar's only with class files.
Use maven manifest tag in your pom.xml, So that you can add entries in your manifest files to locate where is the jar placed. So that when application boot's the jar will take dependency from that location.
While creating docker files, make sure to copy all the dependencies. You can use docker volumes

Related

can we build controller and model classes into seperate jar file and add that jar file as a dependency to another project

Normally in our spring MVC projects, we have atleast config, model, controller packages.my problem is can we build these model and controller directories separately as a jar file and add the resulted jar file to any another project.so that we can get rid of some coding and simplify it
Can we use #ComponantScan annotation to make it work
For this you can use Maven .(
If you are not familiar wtih maven read this , its quite simple- https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html )
Follow below steps
Create a Maven main project with packaging pom in pom.xml file
Then create a maven module for this main project with packaging
JAR where your model is placed.
Create another module with packaging war and add dependency of
module we have created in second step to this project.
Now you build the war project module and jar of first module will automatically added into war
For the component scan question , while creating the different maven modules keep a common structure for packages
For example , You can use com.app as base package name and scan this com.app for beans using componentscan. packages in maven modules could be like this com.app.controller, com.app.model etc
Yes you can add the jar files to another project. You just need to add the jar files in the classpath. First create the jar file of the required package with help of eclipse export option:
Right click on the package and select export.
Go to Java and select JAR file
Give a name to your jar file and continue to click next until the jar is created.
Then make a new folder under the other project in eclipse. Copy and paste that jar file in this folder. Right click on that jar file -> Build Path -> Add to build path. Now you should be able to use those controllers. Just give the correct full package name that you have exported in the #ComponantScan annotation. Let me know if any issue.

In maven how to create jar where lib is outside?

How do I configure my pom.xml so that maven generates a jar where the lib folder and all it's jars are a separate folder outside of my generated jar?
What you need here is to use :
Maven Jar Plugin to copy your generated jar to a different location you want.
Maven Dependency Plugin to copy your dependent jars to a location that you want.
You need to use the outputDirectory property in both the plugins to define the required location where you would like the jars to be copied to, respectively.
Here is an example of the configuration you would add in your POM.

WildFly - Adding JARs to classpath

I am using WildFly 8.2.1.
I need to add specific JAR files to the class path. How can I do that?
Do I need to get inside the module hell?
All I need is to add a couple of extra Oracle JAR files to enable using TLS on the data source connection...
When you build your .war file, add them to the /WEB-INF/lib directory. They will be accessible on the classpath from there. In eclipse the eclipse maven plugin, m2e, will do it by reading your POM file, or of course, maven run by hand will do it.
In the POM file, have it packaged as a war
<packaging>war</packaging>
and declare your jar as a dependency.

How to add a xml a file as dependency using gradle?

I have a project build on gradle and it has a directory src/main/dist/deploy. In deploy folder there is a xml file. This xml file i want to add as a dependency in the jar file which my build.gradle is generating. This jar i am adding in the lib folder of another project that has a dependency on my gradle project. The other project is built using ant. When classes bundled in gradle jar are loaded from ant project they are unable to read that xml file from the gradle jar.
The standard java plugin does not look in src/main/dist/deploy for resources.
You should either move the xml file into java plugin's standard resource folder src/main/resources, or add the dist/deploy folder to your main sourceSet's resource list.

How to make Maven deploy src/main/resources?

I have a Maven project. It is successfully deploying the jar file. I also want it to deploy the contents of src/main/resources.
mvn deploy does not deploy the resources.
How can I make it do that?
I read about using the copy file task and other workaround methods, but I want to use Maven's default behavior for deploying, which I thought would include the resources.
The folder src/main/resources contains resources which will be packaged into the jar file which means in other words it is already deployed within the created jar file.

Resources