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? - maven

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.

Related

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

jar dependencies(available in the POM file ) are not added to the war file.

I'm creating a base framework and distributing it as a jar file. Other developers will use this jar in the web application. others are going to use mvn install:install-file to install the jar in the local repository.
if i try to use the jar in the war , the jar dependencies(jar contains the POM file) are not available in the war. Then i included the pom file in the install command then it worked correctly.
mvn install:install-file -Dfile=path-to-file -DpomFile=path-to-pomfile
The jar file already contains pom file with dependencies,Then why do i need to include the pom file in the install command explicitly.
Is there any alternate ways to pull the dependency available in the jar(POM file) to the war file. otherwise unnecessarly i have to provide the jar and POM file to others.
Thanks,
Sampath
The war project should have its own POM file specifying a dependency on your jar project. In this way, when you build the war, your jar and all its dependencies would be pulled into the war automatically.
In order to distribute artifacts among your fellow developers you should install a repository manager, such as Nexus.

how to make maven war:explode do not pack a jar file

I'm new to maven.
I'm now working on a multi module maven project, when i use maven war:exploded ,it will packaging classes files to WEB-INF/lib/***SNAPSHOT.jar.
Is there any way to leave the classes files under WEB-INF/classes , for when java file changes, there is no need to replace the whole jar file?
Thanks

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