Building a war from multi maven projects? - maven

I have three projects which got converted from Ant to Maven build.
I need help with building a war from three projects.
ex)
proj1 -> proj1.jar
proj2 -> proj2.jar (dependent on proj1.jar)
proj3 -> proj3.war (dependent on proj1.jar and proj2.jar)
When I build a war and open up this war, I see both proj1.jar and proj2.jar are in the lib folder.
Q1. Do I need to explicitly, copy both jar files to my proj3' resources folder using maven-dependency-plugin?
Q2. I also need to copy some property files from each of proj1.jar and proj2.jar 's resources folder?
Do I use maven-dependency-plugin to copy those property files or do I use maven-resources-plugin?
Q3. Before I Convert these projects to Maven from Ant? I had ejbModule (ejb project) folder in my eclipse? In Maven, do I keep this or not? What's the ejb web project's folder structure in Maven?
Thanks much.

Related

while building artifacts with apache maven, it wont build manifest file in JAR anymore (compiler Intellij). Why?

I'm trying to build a jar file with maven with a manifest file, but it won't work. When I build the artifacts from older projects it works, but now it won't. when I build artifacts from old projects, the jars do have manifest files automatically but new ones don't. can you tell me why?new projects with incomplete jar

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.

Building all dependencies in Maven

I have a Ear, war and 2 jar projects in my eclipse.
I want to automatically build 2 jars, war and ear project, when i run the pom inside ear project.
I remember doing this in maven in the past. But i forgot since i lost touch working with Maven for few years now.
Someone please remind me of that..
I used dependency compile, but it is not building jar, when i build the ear directly.
Should i first run pom in jar? does it not build that jar automatically when i build ear?
Create a multi module build that will build it all for you in the reactor. Read more about it e.g. http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-pom-best-practice.html#pom-relationships-sect-multi-vs-inherit
I guess you should define tha .jar and .war projects as dependencies of your .ear project. It is also advisable to have a parent pom, where all the projects are defined as modules, including the .ear project.
In this book you can find a well explained step-by-step setup of a maven multimodule project (with downloadable code).
There is also a great working example of an enterprise multimodule project in the JBoss quickstart examples.

Maven build - include classes in projects /src/main/webapp/WEB-INF/classes

We have to build ontop of an application that we did not develop and we need to include some classes from the Jar's WEB-INF directory. How do we get maven to do this? The eclipse deployment directory includes this for local deploy but the built war looks different and does not include the files we place in the source.
You can use the dependency plugin unpack dependency option to unpack from a dependency and output it to a location you desired.
http://maven.apache.org/plugins/maven-dependency-plugin/unpack-dependencies-mojo.html
Or alternatively, you can use the maven assembly plugin's unpack describtor to achieve the same thing.

how to include dependency classes to war project's WEB-INF/classes folder in maven

I've a project B which has a dependency on project A. Both project's packaging is jar. Another project C packaging is war. Project C contains no java classes. It contains only webapps folder. Project C has dependency on project B. I want the war to be packaged in just a way that all the java classes from Project A and B should be copied to WEB-INF/classes folder. How can we achieve this ?
You can use the unpack goal of maven dependency plugin in your pom to unpack the desired dependencies to a folder and ensure maven war plugin includes this folder.

Resources