Hi I am converting a ear project to Maven. Below is the structure
-projA-ear
-projA-static
-projA-web
-shared-util
The shared util is shared by multiple unrelated projects handled by our team. Currently my deployment assembly is handled by eclipse and the shared-util.jar is automatically built inside the projA-web.war's WEB-INF/lib directory
When I convert my setup to Maven project, I am reading that I need multi module aggregator setup, and need to define shared-util as a module, and then define the aggregator POM as the parent to my modules. The problem is I cannot define projA-mvn as parent in the shared-util project as the other projects would be using it too as a module(when they decide to move to maven). Can someone please suggest a solution?
1) Make shared-util as a separate standalone Maven project.
2) Put projA-ear, projA-web and projA-static under a separate parent Maven project.
3) Declare shared-util jar as a dependency in your projA-web pom.
Related
I have a core webapp and want to extended it by several optional modules (jar files).
These modules can contain Servlets, Filters etc.
Development:
Since the modules are optional I think that using maven modules with a parent is not the way to go,
because the parent always contains all modules and I do not want to have a parent per deployment scenario.
So a normal maven project per optional webapp module... But how do I manage that the core and the module always use the same dependencies?
Do I have to create a parent pom for both which contains all the dependencies and other shared settings (Java version etc)?
Deployment:
What is the recommendation here? Always repackage the war? Copy the module jar into the exploded WEB-INF/lib?
Could it deployed at runtime too?
It sounds like you are looking to configure and build all the possible configurations seperately instead of using or making some truly dynamic module loading system.
In that case the simplest way is to have a war-project per configuration:
You should have a module pom-project that does nothing but build all other projects. This could be the parent project, but I would use a seperate project. EDIT: I would place this project in the root of your repository and place all other projects in sub-folders. That goes well with IDEs and release tools.
You should have a parent pom-project that does Maven <dependencyManagement> for managing all dependency versions in all projects and has any general build configuration that all other projects need. All other projects except the module project has this as parent.
You will probably need a common jar-project for common code used in many modules.
You should have a jar-project for your core application.
You should have a jar-project for each module.
For each configuration you need a war-project that is nothing but a pom-file declaring the needed dependencies and mayby some property files. They will build your products.
If you want to have special configuration for the war-projects (deployment, test etc.) you can make an intermediary parent for them. It should have the general parent as parent.
Now you can build everything with the module project and end up with a war-file for each configuration.
In Eclipse, I have two projects:
archangel.core - a Maven project
ArchangelWEB - a Dynamic Web Project (built for Tomcat).
The first, archangel.core has all of the base code and uses Maven to resolve dependencies. The second is the Web addition on top of the core project. This only has code specific to presentation/view. I want to keep them separate because I may have other projects in the future that will rely on the core, and I don't want the core project to have Web Library dependencies.
Right now, in ArchangelWEB's build path, I have the archangel.core project, and I also have archangel.core in its Deployment Assembly. This allows me to refer to code from archangel.core in ArchangelWEB without any build or runtime problems.
One of archangel.core's dependencies is apache-commons-lang. Within archangel.core, I can reference classes like ExceptionUtils. However, I cannot automatically reference this jar dependency from ArchangelWEB. If I try to import class from apache-commons-lang in ArchangelWEB, it doesn't know what I am talking about.
What is the best way to import/reference dependency jars from a maven project into this other project (my Dynamic Web Project), which uses the maven project as a dependency?
Dynamic Web Projects resolves dependency only by manually placing the Jars in the WEB-INF/libs folder. There is no other way.
So you need to place the dependent jars of your Dynamic Web Project into the libs folder manually.
Don't forget to do Right-click the Jars in Lib -> Add to Build path after adding them
This is why we use maven these days instead of the old Dynamic Web Projects.
How can i combine two maven projects. One is webapp, and other is some javascript library (also webapp) which i want to combine with others project.
Or, would be better, how to add some outside folder with js files to maven project that can be deployed on testing server and then build to war.
Have a look at overlays in the Maven WAR Plugin documentation. This explains how Maven merges resources from different web projects into a single WAR.
In a nutshell, you create several WAR files of all the dependencies (usually, you already have this but you can even do this if they aren't real working web projects). Then you can pull these in as dependencies. The important part here is to specify the type of the dependency (<type>war</type>); otherwise Maven will try to add the JAR.
The WAR plugin will notice the additional WARs in the list of dependencies and merge them.
You can create One parent project and Two modul project. You will have 3 pom.xml files.
modul projects extendens dependencies from parent project. Maven parent pom vs modules pom, Multimodule project
Maven WAR Overlays could solve the problem. If you have two maven web projects, and one of your Web Project depends on the other's you could declare the dependent project as a dependency and do an overlay.
Reference:
http://maven.apache.org/plugins/maven-war-plugin/overlays.html
I have two questions about maven project structure:
1) I am creating a maven multi-module project and would like to know if I can put all the common dependencies of the modules in the parent pom? Is that the right way to do?
2) If I am creating a maven webapp project that contains all web.xml and JSP files, where should the web controllers, listeners and model objects be residing? In a separate maven jar project or in the same webapp project?
1) Read up on the difference between dependencyManagement and dependencies. Putting all common dependencies in the parent POM will work, but it's likely to cause spurious dependencies when you add a new module.
dependencyManagement is recommended. You can specify all versions and exclusions in a central place, and then it's enough to specify groupId and artifactId for each dependency of each module.
2) Java sources directly related to the web layer usually go into the war module (unless you want to reuse them for a different project, then it's better to factor them out into a separate jar).
its regarding building an existing EAR using maven which contains multiple modules .
we have a EAR project which contains web and jar projects in it total of 8 projects.
ear was built using RAD and hence currently non of the project is having POM files .
now i want to use maven for project.
i want to use m2eclipse for creating POM's and build.
plannig to creat a parent project and create modules under it, which includes ear project and others as well.
so effective structure should be as below
workspace
>parent proj
>ear project
>web proj
>jar1 proj
>jar2 proj
but i have ear file containing all the projects and if i import ear in work space it create flate structure for all the projects as below
workspace
>web proj
>jar1 proj
>jar2 proj
concern is becuase of RAD project setup and .metadata files created by it in workspace.
if i create parent project in workspace and then import ear in parent its a problem.
please advise how can i do following
1> add indirection of parent project and below it have all the projects in ear
2>how to add ear project under parent which hold all the modules at build time
hope my situation and requirment is clear
please advise on it
Thanks
narayan
You shouldn't have to import the ear into the parent project, the parent should just reference the ear as a module in its pom, and appear as a subdirectory within the parent.
Perhaps I'm unclear of what you mean by import.
The order that the modules are declared in the parent pom is the order in which they are built, so the ear should be the last module in the list as it has jar1, jar2 and web modules as dependencies.
web should be the second last module in the list because it presumably depends on jar1 or jar2 or both.
M2Eclipse has the ability to import a multi-module project structure that you described above as separate projects within the workspace, choosing this option prevents you from having to work on each individual module through the parent project and expanding all the way down.
This does not change the nested structure on disk, it merely presents the modules each as their own project, and the module directories are also visible in the parent project.
It also allows each module to be built individually, or a complete build can be performed by building the parent project.
Read about maven reactor in this question.
I suggest that before you tackle your main project try out a quick archetype, see http://docs.codehaus.org/display/MAVENUSER/Archetypes+List
The appfuse archetypes by Matt Raible are really good examples to work from, try the command below to create a skeleton structure:
mvn org.apache.maven.plugins:maven-archetype-plugin:2.0:generate -DgroupId=com.test.archetest -DartifactId=archetest -DarchetypeArtifactId=appfuse-modular-jsf -DarchetypeGroupId=org.appfuse.archetypes
Have a look at the general project structure, and then import it using M2Eclipse which will generate the eclipse project files..
You could also do this through mvn eclipse:eclipse, but that won't give you the separate modules in your workspace.
Some project choose not to commit the eclipse project files, and rather have then generated from the pom through either of the methods mentioned above.
If you use the structure from the archetype given above, then you'll need to add an ear module to the parent project, this can be done through M2Eclipse.
thanks #crowne
instead of hierarchical structure i can use module approach.
to wrap all the existing projects, create a maven project of packaging type pom in same workspace
then existing projects can be added as modules as below
../module1
../module2
../module3
path specified are alway relative to location of pom in which modules are declared.