Maven Enhancing / Exploding war file - maven

first of all sorry if this is a stupid question, but i am quite new to the topic of Maven. So please correct me if i am doing something wrong or not best practise like
Currently I have following issue:
I have an 3rd party application in several war-files which i would like to extend (this 3rd party party allows to extend the software with own individual implementation).
Therefore i have created a Maven Project where i added the required war-files as dependencies in my pom.xml
My assumption is:
I have to somehow unpack the war file and then have to add my new implementation to it and then have to compile everything and then have to repack everything into a new war.
Is that correct or not?
How would i do it?
Thanks a lot for your help

The Maven War Plugin supports overlays that allow you to do exactly what you desire.

Related

The idea behind using maven to compile source code

I am currently starting my adventure with Maven, and I actually don't understand the idea behind using it to automate compilation of my source code. For the time being I am working on small projects with up to 15-20 classes, and 1 main method in the "app" class. Could someone please give me the explanation with examples, when it's necesarry (or recommended) to use build automatation tool to compile the source code and how could I benefit from using it regarding source code compilation?
Thank you very much in advance!
I was looking for different answers and I have a lot of work to do but since I've seen this question, as a Maven fanboy, I couldn't resist anymore and this below is my answer.
First of all, I agree with JF Meier which answered before me, but I think the answer can be improved.
IMO you have to consider Maven not just as a build tool, but as a multi-purpose tool which can help you to do very different things. The best 3, for me are:
Compiler. Obviously. Maven allows you to easily compile giant projects with a lot of submodules, even if some of these modules are interdependent one with each other.
Dependency and repository manager. Maven allows you to automatically download third party software and bind this downlaod to the build. This is immediately understandable if you think to framework or api dependencies from big corps (Apache found., Spark, Spring, Hibernate and so on ...) but it's really powerful in every enterprise context.
Example: you have a Maven project (let's say project A) which manages requests coming from a webservice and provides responses. This Maven project relys on another Maven project (let's say project B) which actually generates webservice jar and uploads it to a company repository. Well, when you have to add a field or a method to the webservice you just have to implements new software in project B, upload it the repo and change the version in Maven poms in both project A and B. VoilĂ : now EVERY developer of the company just have to "mvn clean install" project A to have the new version.
Sources and code automatic generator. Since Maven 2.x are available a lot of plugins (from Apache found. and others) which allow you to generate code and sources (tipically xml files) starting from little to none implementations.
Example 1: CXF plugin is commonly used to generate java classes from xml or xsd files.
Example 2: JAXWS plugin is commonly used to generate wsdl from SOAP webservice implementations or implementation starting from wsdl file.
Do you feel the power now?
-Andrea
The question is not very specific, but I will try to answer.
Usually, you want your source code to end up in a jar or war, so that you can use it as a library or run it somewhere (e.g. on an application server).
Maven not only compiles the classes you have and creates the final artifact (jar, war), but also handles your dependencies, e.g. the libraries your project depends upon.

Is it possible to add dependencies in a pom.xml file?

My question may seem very simple but I did not know how to write it correctly ...
Here is my problem : I am testing an application using Cucumber and other libraries.
To do that, I had to add different dependencies to the pom.xml file of the Maven project I am testing.
In order to use all the work I made for further projects, I am now trying to create a settings.xml file in order to configure all others Maven projects with this document (avoiding copy/paste for all the pom.xml files). The fact is I manage to create profiles (which eases a little the work) but I can't find a way to automatically include all the dependencies I need.
Is there an easy way to do that ?
I hope my question is clear,
Thank you
You can't add dependencies from settings.xml profiles.
You need to add them in projects pom.xml files (or in the parent of those).
Thank you all for your answers !! I think I will have no other solution than copy/paste each time all my dependencies then...
Regards

How to work with MAVEN and SBT in two different projects?

I'm working in a project that uses MAVEN. And another project which uses Play Framework and SBT, this uses the first project as dependency. But how can I resolve the dependencies of the first project into the second project ? Since that SBT doesn't read pom.xml natively. And how to make this maintainable ? I mean, I don't want to have to maintain two different files all the time, I want to this integration to be smooth.
My current approach
I'm cloning/pulling the first project, resolving its dependencies with maven, as I normally would do it with maven, right ? Also I'm getting my first project as dependency from Amazon S3 with aws-maven.
And then I just set in my second project to use my local maven repository.
Is this a good approach ? I think it is because I can combine the best of two technologies. But I might missing some point here. Please advice.
I tried to use some plugins (1,2) from sbt to read my pom.xml file but I have faced several issues (1,2) which makes me to give up trying to use them and go forward with a more native solution.
What do you guys think ? Any suggestion or advice ?
Since you publish your first project to S3, you might want to use this plugin for your second project: https://github.com/ohnosequences/sbt-s3-resolver
Which do the same thing as the aws-maven plugin. So you can get the first project as dependency of the second project and be able to work with them on other environment as well.

Incorporate large number of 3rd party jars into maven

I'm working on a project that has a reliance on a significant number of 3rd party jars; these jars contain both proprietary classes and custom/patched versions of existing libraries. I'm trying to figure out how to tie these jars into the maven architecture so as to be CI friendly.
My initial idea was to create an uberjar of all these libraries, and add that one uberjar to the maven repository, however I have not been able to figure out how to take this set of standalone jar files (that are not dependencies) to merge like that. There exists lots of documentation on how to uberjar a project and its dependencies, but not standalone jars.
I feel like i'm missing something basic, or maybe there is a better way. Any recommendations are welcome.
You would be better off to proceed as follows:
Set up a repository manager.
Write a shell script that runs mvn deploy:deploy-file for each of your jars, generating the GAV with a simple algorithm.
treat them like anything else.
To elaborate on Step 2:
G:A:V - my-company-name:name-of-jar:version-based-on-todays-date.

Maven shipping scripts

I am completely new to Maven and come from an ant world. I am having lots of trouble something that might be really trivial.
I want to have a maven project that is made out of non-code items that I want to ship along my jars. These items are DDL scripts, installer scripts a couple of utility scripts, readmes etc.
I do not want to use "resources" in the corresponding java projects since I do not want them living in the actual product jars. I want them shipped as separate artifacts that just like any other jar.
It is acceptable to bundle them up in a jar or zip, etc.
Is there a way to do this?
Thanks!
Use the build helper plug-in to add additional artifacts to the Maven module.
Check out the answer to the following question
Ok, I found it and it was pretty simple. Just created a project added a simple pom with no plugin pacakging jar and I create the proper dir structure
src/main/resources/...
This builds it into a jar

Resources