how to include dependency classes to war project's WEB-INF/classes folder in maven - 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.

Related

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?

Building a war from multi maven projects?

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.

Building/deploying a EJB .jar with its dependencies

I am new to Java EE. I use Maven, Eclipse and jBoss/WildFly.
I have a war project. When I build the project all its dependencies are packaged inside the war file in WEB-INF/lib.
Now I am trying to create a ejb project (I have <packaging>ejb</packaging> in the pom.xml). I want to deploy it as a separate project (not as a part of the war). When I build the ejb project Maven does not package any dependencies in the jar.
How can I package/deploy a ejb .jar with its dependencies?
UPDATE: I'd like to avoid packaging EJBs in an .ear if it is possible. (I do not want to create one more Maven project).
The best solution is package your project as ear. But if don't want use ear, maven assembly plugin can help you to package all needed jars in one file. This solution is only for "proof of concept" variant, and cannot be used in production mode, by licences limitation for example.

Combining jars for multi modules maven project in a single jar

I have a parent maven project that includes some child projects and a build/assembly project. The structure looks like this
ParentProj
+ pom.xml
+ ChildProj1
++ pom.xml
+ ChildProj2
++ pom.xml
+ buildProj
++ pom.xml
I want to create an executable jar in the build project, or project that contains all child project jars. Basically the final result should be a jar that includes all child project jars in the classpath.
Your project buildProj should have the other child projects declared as dependencies, you could then configure the maven assembly plugin to use the predefined descriptor jar-with-dependencies which create a jar that contains the dependencies.
How can I create an executable JAR with dependencies using Maven?.
https://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html
EDIT
If you wish to add the dependencies jar in your jar, you could use something like onejar:
Creating a JAR file which contains other library files
http://one-jar.sourceforge.net/
There is a maven plugin for this tool: https://code.google.com/p/onejar-maven-plugin/

Include java webapp lib in maven build

I was having a dynamic webapplication created on eclipse. I converted it to a maven project using M2E plugin. I added maven war plugin in the pom.xml so that it can create war for my project using maven build.
But when I do the build, it fails to compile few classes which has reference to the jars of my webapp/Web-INF/lib folder. These jars I can't include as dependency in pom.xml.
How can I tell maven to include Web-INF/lib jars also while building classes and creating a war?
Its not correct way of doing this , you should not put any jar manually in WEB-INF/lib folder.
And if that jar is not available in MAVEN CENTRAL REPO , then you can download it and install it in your NEXUS CENTRAL REPO (if you have any) otherwise put that jar in your local maven repository and add it as a dependency in your pom file. If you don't want to include that jar in your WEB-INF/lib then change the scope to provided otherwise leave it as default i.e compile.
During build time MAVEN will look for that particular jar in your local repo first , and if it don't find it there then it try to download from Centra Repo.
Once it is available in your local repo , your build won't break.

Resources