Maven - Which build phase? - maven

I have a Jetty embedded project.
I configured the package phase, using maven-shade-plugin, to create a jar file. It creates a jar file on target folder.
I need to copy some a folter, containing some javascript/html. Which phase do i have to use? the same package phase?
thanks

It depends on what you trying to archive - building a jar containing ressources such as javascript and html files Maven will automaticially include those resources if you place them under /src/main/resources unless excluded in the pom.xml in the phase package (the same and only non-plugin available phase package of the default lifecycle of Maven).
If you on the other hand want to build a webapplication you normally specify the packaging to be a war leading to a *.war web archive. In this case you would normaly place script and html files somewhere under src/main/webapp/WEB-INF as described here: http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

Related

maven-antrun-plugin copy resources works only on validate phase

I am using maven-antrun-plugin version 1.8 to copy some files to the src/main/resources folder so that it gets included in jar in package phase.
If the execution phase of the task defined to copy to resources folder is validate everything works fine but if it is compile/test the files are copied to src/main/resources folder but are not included in jar
It is because Resources folder gets copied to target folder at process-resources phase of Maven. Therefore to get files in the resources folder of jar/war you need to copy files to resources folder before the process-resources phase i.e. you can pick validate, initialize and generate-sources phase of maven for same.
It is important to understand the Maven lifecycle. Bind the Antrun plugin to an early enough phase to achieve what you want.
That said - consider packaging the other resources into a jar and then adding that jar as a dependency instead of adding Antrun plugin invocations. Or, use the Assembly plugin.

How do I build an exploded WAR in a multi-module Maven project and also include sibling JAR files in its WEB-INF/lib directory?

I’m using Maven 3.3.3 with the Maven WAR 2.6 plugin. I have a multi module project with both JAR and WAR projects within it. My WAR projects depend on my JAR projects, however, I do not want to package my WAR files, opting instead to keep them in an exploded form. So I tried running this command
/usr/local/apache-maven-3.3.3/bin/mvn -B -f /home/jboss/.jenkins/jobs/subco/workspace/pom.xml -B clean prepare-package war:exploded -DskipTests -T 3
Although this keeps my WAR exploded, the JAR projects do not get included in my web application’s target/myproject/WEB-INF/lib directory. Instead what is included are empty directories where my JAR files would have been, for instance
.jenkins/jobs/subco/workspace/myproject/target/myproject/WEB-INF/lib/child-jar-module-2.0.0-SNAPSHOT.jar/
How can I keep an exploded WAR, include my JAR files, and do it all from the command line (as opposed to creating a custom profile in my parent pom to do it for me)?
Edit: If you think this is a duplicate of another one, notice the part of my question where i point out that empty directories are generated when using the "prepare-package" phase. I don't want that.

How to add folder inside src/main/app in Mule project directly inside zip file and not in classes when building using maven

I have a folder named webapps inside my src/main/app in mule project. This webapps folder contains a war which is exposed in mule-config.xml through jetty connector. I tried lot of combinations in my maven build but this webapps folder ends up inside classes in zip file. I want it right inside zip.
Any pointers how to achieve it in pom?
Try using the maven ant plugin.
File can be moved around after compilation and before packaging.
phase: prepare-package (just before packing)
https://maven.apache.org/guides/mini/guide-using-ant.html
Hope this helps.
Since couldn't get maven to build zip file in a way that it would copy webapps folder directly under root. I ended up placing webapps folder containing war file inside src/main/resources. Maven build copied webapps folder under classes. And the mule-config referred it as
<jetty:connector name="Jetty" doc:name="Jetty">
<jetty:webapps port="${jetty.port}" host="${jetty.host}" directory="${app.home}/classes/webapps" />
</jetty:connector>

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.

How to include dependency files in maven assembly

I have a maven project which is configured (via the use of pom.xml and assembly.xml) to package a zip file containing both the compiled webapp (war file) and all files under src/main/folder alongside it whenever we run mvn clean package assembly:single.
This project imports/uses another maven project (which becomes a jar file) and that project in turn also imports/uses a third maven project (again a jar file).
The third project also contains some files inside src/main/folder as well which I'd like to be placed alongside the other files in the zip file whenever I build the main project (the one on top of the chain that becomes a war file).
Is it possible somehow to tell maven to include all files in a specific folder inside all it's dependencies (Or in one specific dependency) alongside in the zip file?
Start here: Maven: The Complete Reference - 8.5. Controlling the Contents of an Assembly
Note that if you deploy a Maven project with assembly:assembly (which you really should configure as a <build> plugin, not use on the command line), the assemblies get "attached" to the project and installed in the repository. You can then reach them using the Maven dependency notation, i.e. mygroup:myartifact:extrafiles:zip
I've found the Assembly descriptor <dependencySets> cumbersome to configure. They really are for the simple case (including the JAR files your application needs at runtime).
Here is the general approach I would take for your desired outcome:
Use Maven Dependency Plugin dependency:copy to download the specific files from the other projects, placing them under a sub-directory of target/
Configure your assembly descriptor to add those downloaded/extracted files to your final assembly artifact.
Alternatively, hack something together using Maven Ant Run Plugin.
You will need to produce an additional assembly from the third project to package up the extra files. Append the assembly id so it produces a package named something like third-1.0.0-extrafiles.zip
Then add this as a dependency of your first project using <type>extrafiles</type> in the dependency descriptor. In the assembly for the first project you'll have to tell it to "unpack" the dependencies of this type (so you don't get a zip in a zip)

Resources