How to add folder inside src/main/app in Mule project directly inside zip file and not in classes when building using maven - 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>

Related

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.

Maven - Which build phase?

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

How to place context.xml in war's META-INF?

I am building a webapp through Gradle's war plugin. In order to disable Tomcat's session persistence, I need to place the file context.xml in the META-INF directory of the war's root.
I attempted the following:
Create the file src/main/webapp/META-INF/context.xml of the main project
Create the file src/main/resources/META-INF/context.xml of the main project
However, when I build the project using gradle clean war, the produced war file contains a META-INF with only a MANIFEST.MF in it. It is as if my directory gets overridden.
How do I place context.xml in the war?
src/main/webapp/META-INF/context.xml is correct and works fine for me. Chances are that you went wrong somewhere, or that there is a problem with your build script.

Maven update contents of an EAR file

I have an EAR file which I want to update. I do this in Ant by unzipping the EAR and then the JAR, replacing a few files and then repackaging it.
I am trying the same with Maven but with little success and it is also confusing.
So far I have done
1) installing the EAR file in the local maven repository
2) unpack it
3) Replace the file I need
Now I am not sure how to get back the new EAR file. Everything is in the repository.
From my understanding, the EAR plugin packs everything in the ejb, war folders and spits out the ear. But since I directly got the EAR file, I do not have any project per se.
Any suggestions on this?
Also is there a good tutorial on Maven?
Thanks,
You should probably perform the following steps, using a "blank" Maven project and assuming the EAR file is already inside a repository (pushed by another project/tool):
use the dependency:unpack mojo to get and unpack (inside the /target/ folder of your project) the EAR
modify the contents
use the assembly plugin to repack that EAR file
Then do what you need to do with that new EAR file.
A "blank" Maven project would mean that it will not act as a usual project (compile sources, package output...), but rather serve to manipulate existing artifacts through specific plugins.

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