Merge files from multiple war file - maven

I have a main war file with maven dependencies to various war files. With the maven-war-plugin I am able to merge them into one, but my problem is, if files with the same name exist they will be overridden by the last one.
What I want is to merge the files with the same name.

This is not something done commonly with Maven. But have a look at the discussion of this SO question: How can I merge resource files in a Maven assembly?

Related

Jenkins Job - Creating a zip file with war file, appspec.yml and scripts folder

I have created a build with Jenkins for a spring boot application and it is creating a war file.
Now I want to create a second job which should create a zip file with the war file created and appsepc.yml file and a folder "scripts" folder which contains some shell script that the appspec.yml file uses. Can anyone let me know how to do this?
The job name is "Package" so the following is the structure where the different files are.
.jenkins\workspace\Package\target\cpproject.war
.jenkins\workspace\Package\appspec.yml
.jenkins\workspace\Package\scripts\after_install.sh
.jenkins\workspace\Package\scripts\before_install.sh
.jenkins\workspace\Package\scripts\start_server.sh
.jenkins\workspace\Package\scripts\stop_server.sh
Thank you.
See the Maven Assembly Plugin:
The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files.
Currently it can create distributions in the following formats:
zip
...

Maven: how to copy a directory cleanly before creating the JAR?

I want to store some additional files in the JAR that gets created. Those files are in a directory that is a subdirectory of a repository which is pulled in via a git submodule.
I want to copy that submodule to my src resources directory before compiling, but I also want to make sure that any old files at that location are removed first.
How can that be achieved best with Maven plugins? I did not find any option to remove any destination files with the copy-resources goal of the maven-resources-plugin and I could not get the maven-clean-plugin to run right before the copy-resources either. So how does one accomplish such a trivial task with Maven?
UPDATE: as mentioned above, the reason why I want to do this is because what is copied should become part of what gets added to the resulting jar (and could potentially be part of what gets compiled). So I need to copy these files into the src directory and NOT the target directory. What should get copied before each build is the input to the build, not an additional output.
There is one flaw in your approach, and it probably explains most of the obstructions you encountered.
During a build, the only directory in which you may write is target. Copying files to src or changing them is strictly discouraged.
The target folder is erased by clean, so no need to tidy up yourself or to manage old files.

How to copy directories into WAR using Maven?

My goal is this: I have 2 directories (not their contents but the directories themselves) which I need to get copied into both the exploded WAR directory and the packaged WAR.
Specifically, I need the following directories inside the final WAR:
${project.basedir}/web/WEB-INF/templates needs to get copied into
target/${finalName}/WEB-INF/
${project.basedir}/web/WEB-INF/classes/dao needs to get copied to
target/${finalName}/WEB-INF/classes/
So far, I haven't found any way of doing it. I've tried the resources plugin, the war plugin's webResources feature, antrun, exec-maven-plugin, etc., and each have limitations that prevent the aforementioned directories from ending up in the final WAR. In some cases the resultant directory structure ended up with too much nesting (e.g.: target/${finalName}/WEB-INF/classes/WEB-INF/classes/); in other cases nothing got copied at all, presumably because the war plugin has its own beliefs about what should and should not get copied.
As such, I'm at my wit's end. Is there any way to copy actual directories without having the war plugin question my motives? I wish I could tell Maven, "Do as I say!"

In Maven, how to copy all the files in the target/surefire-reports directories to a single directory

I have a largish Maven multiproject build. I'm scanning the codebase with SonarQube (5.6.5). For background, I successfully integrated the various JaCoCo exec files into SonarQube by using the "jacoco:merge" goal, to produce a single exec file. The SonarQube property that alleges to allow specifying a list of JaCoCo exec files doesn't work in our version of SonarQube, but specifying a single one does work.
I'm now trying to integrate the numerous "TEST-*" files in "target/surefire-reports" in each of the subprojects. The "sonar.junit.reportsPath" property expects a single directory, so I can't specify a list of them.
That means I'm going to have to do something as part of the build to merge the entire contents of all of the "target/surefire-reports" directories into a single directory, so I can specify that directory.
I already have a pom that does nothing but merge JaCoCo data. This seems like a logical place to store the surefire reports.
How can I do this sort of thing with Maven? Would this be an application of the "maven-resources-plugin", or something else?
Ok, well, I guess I answered my own question. I was able to get this to work with the resources plugin, specifying every one of my modules as resource directories. I now have one ridiculous-looking POM that has three lists of all of the modules in my multiproject build, for three tasks that require me to list all of the modules to process. The Gradle version would be amazingly short.

What is an exploded EAR?

Can someone please explain what's an exploded EAR ? I checked in google but couldn't find a clear answer.
Is it a different format?
What's the difference to a non exploded EAR?
A compressed EAR file, with extension .ear is just a ZIP file containing the directory structure of a JEE project. It is normally used in order to deploy a JEE project.
An exploded EAR file is just the uncompressed content of the above.
Incidentally speaking, war and jar files are also compressed in ZIP format.
The use of the wording "Exploding" instead of "decompressing" a ZIP file seems to be traditional in the java community, and is present in official documentation.
E.g.: www.java2s.com/Code/Java/File-Input-Output/classforexplodingjarzipfilesontothefilesystem.htm (on a IBM contributed source file belonging to Eclipse ).
They can be exploded with the jar command.
You can also use any compression utility, provided you keep the directory structure intact.
e.g.:
jar xvd /myapp_path/myapp.ear

Resources