Build child jar using parent war using maven - maven

I need to create a dependent maven project.
The child one should be a jar, that would be called by the parent project which should be a war file.
The steps should be like this. When I build the war, it should automatically build the jar file and include it and build the war and show output of the child jar (suppose a simple print statement).
Note: Build should be done only once and that is for building the final war.
Need to edit the pom.xml accordingly.
I am new to maven,so a bit elaborate solution would be very helpful.

Related

Maven goal to move file to another directory

I need to move the war generated to some other directory with maven goal.
I know how to move it to another location by adding configuration in pom.xml but i need to do it with a goal.
Which i can run directly without using pom.xml
like: mvn jboss-as:deploy-only deploys jboss with war generated without including any plugin specific configuration in POM.
Their are some restrictions to plugins which can be used in pom. So need to use Maven Goal only

How to create ear using using another project war through multi module approach

I have one maven project(lets say Proj1) which creates a war file. I want to create a parent project(lets day Proj2) which will create an .ear using the war project. So that when I build Proj2, it should build the war from Proj1 and then use it to create .ear
What you need is your project to be structured this way:
Parent project (packaged as pom)
-->Child-EAR project (packaged as EAR)
-->Child-WAR project (packaged as WAR)
Each project should have a pom file, parent project should include the child projects as its module. The child project should include the parent module. Please see this link: https://www.javacodegeeks.com/2014/04/java-ee7-and-maven-project-for-newbies-part-1-a-simple-maven-project-structure-the-parent-pom.html it explains in detail.

Compile a jar during Maven build then package as ear from single pom.xml?

I have a maven project currently structured that has to build a jar first from some source files, then create an ear file containing that jar along with some other xml resources. The way I do it at the moment is by building the jar seperate in a 'child' pom.xml then at the root of the project folder I have a parent pom that does the ear packaging.
I know it isn't ideal, but I what to be able to compile the jar and then package it into an ear all with just one pom.xml file. Any ideas on how to do this?

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: Get artifact list of sub modules

I have a root parent maven module which has lot of sub-modules that build jar files as artifacts.
I cannot change all sub-module pom.xml files.
From the root parent pom.xml is there a way I can get a list of all jars (artifacts) built by sub-modules?
Preferably after the package phase is complete?
PS: As a part of root module build I want to generate a report using a tool which requires this list of jar files.
There's a target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst in a Maven project.
You can use the GMavenPlus Plugin and Walking the File Tree to gather these files and put their content where you want.
Another option is to develop an own Maven plugin that does the same.

Resources