I have a maven project which currently creates a war package on build. Now I need to bundle it as an ear project. Any pointers on how to do this. I added the m2e plugin and modified the pom.xml file, but, i am not able to get the directory structure as expected. I need the dir structure as below
project-name
- project-name.ear
- pom.xml
- project-name.war
- projec-name.jar
- META-INF/application.xml
Thanks.
It is strongly recommend that you organize your project structure in proper Maven style:
project-name/
- pom.xml (POM of project-name, multi-module POM)
+ project-name-jar
- pom.xml (main app JAR)
+ project-name-web
- pom.xml (WAR project to construct WAR by project-name-jar etc)
+ project-name-ear
- pom.xml (EAR project to construct EAR by project-name-war etc)
Normally I will have another child project call project-name-parent which use as parent POM for the whole project.
In Maven, you don't and you shouldn't have META-INF/application.xml as part of your source. It is generated dynamically base on configuration of maven-ear-plugin.
Related
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.
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?
I want to create a Maven project. I want it to have a parent project. The problem is that the parent project has a package in: war.
I see an error :
Invalid packaging for parent POM must be "pom" but is "war"
What should I do ?
A parent project (packaging with type pom) is by definition a container of submodules. Only the submodules are allowed to be of specific packaging types (like war or jar). You use a parent project to aggregate common dependencies and build configurations.
I suggest that you put the code you want to reuse in a submodule of type jar and then add this submodule as a dependency of other projects you have (with packaing type war or jar).
You could read Chapter 6 of the book Maven by Example where it illustrates how to build a maven multi-module project.
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/
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.