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.
Related
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.
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
What is the difference between maven multimodule project(pom packaging) and ear packaging.
As i know Ear is used to package a group of related Module (EJB, JPA, JSF).
After reading maven documentation i found that multimodule project is used for the same thing.
Are they the same? Can i use multimodule project instead of EAR? can mutlimodule project be deployed to application servers?
A multi-module project (packaging of pom) is a way of defining a parent pom that has child modules. This is convenient for many reasons. For one, you can just build the parent pom with mvn compile and it will build all of its modules, too. Without the parent pom, you'd have to go into each pom and manually type mvn compile otherwise.
Not only that, but using modules gives you other really important features. See the answer to this question. To summarize, imagine you have a continuous integration server that just installed in the middle of you building locally. By using module, you ensure that you compile against your local code instead of the continuous integration server's code. This will prevent a lot of heisenbugs(sp?).
Now the packaging of ear is not directly related to this first multi-module concept. That packaging just determines the binary output. It will output an ear file. In the maven-ear-plugin plugin, you can include other modules like wars/jars/ejbs, but it won't do any of the things I've described in the first paragraph. For example, typing mvn compile in the directory of the ear's pom.xml file will not compile the war file it depends on.
Also, you don't have to include other maven modules in your ear. Another completely unrelated project may install an ejb and you can use that ejb in your ear just as a dependency.
multi module is just a way of organising your project into modules/components.the packaging need not be ear always.it can be for instance a war project that has all its server side content as a jar file in one of its module.
in short,multi module organisation can be opted for a ear project but the converse that mutli module is always a ear project is not true.
The two are not the same. A multi-module project just builds all sub modules, it does not produce an artifact.
I have a project with a number of POM files. I have done a clean install and eclipse:eclipse. I would like to import the project as a normal project rather than Maven project. When I imported the project as normal project , I was not able to see the Maven dependencies present in POM in eclipse's build path. Is importing the project as Maven project only way of doing it? When I import the project as Maven project I see a number projects in eclipse workspace (one for each POM). However I would like to view this as a single project in eclipse workspace.
UPDATE: The classpath files of the child projects contain the dependent jar files , however it is not added to build path when the main project is added. Only the entries in classpath file of the main project is being added.
Given that you refer to "Maven project", are you using an eclipse plugin for Maven like M2Eclipse?
Assuming you are using M2Eclipse, the Maven Dependencies Library is automatically enabled for a Maven project. For a normal Java project, importing the library would force you to configure the project as a Maven project (On the context menu for the project, select Configure -> Convert to Maven Project).
Having said that, while you import your Maven project, you will notice an "Advanced" option (towards the lower section of the "Import Maven Projects" dialog). When you expand this option, there will be a checkbox to "Resolve Workspace Projects" - this is checked by default and is hence responsible for importing the child modules as separate projects. If you uncheck this, it will import only the parent module as the project and all children modules will be in sb folders under the parent module.
IMO, resolving the projects provides greater clarity, but then again this is very much a personal choice.
Hope that helps.
Eclipse doesn't support nested projects, and Maven kinda forces you to. So you can't really push everything into one project.
Doing a cursory google search led me to this, which might be helpful: http://warpedjavaguy.wordpress.com/2011/08/08/how-i-defeated-the-maven-release-plugin-in-a-flat-structured-multi-module-project/
You might also check out the following two online books from Sonatype:
Maven: The Complete Reference and Developing with Eclipse and Maven
Personally, I create Working Sets for each multi-module project and add all the individual projects to it. This enables me to see them all grouped together, this might be to your liking.
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fcworkset.htm
Once you have created the working set you can enable/disable them in the menu in Project Explorer and configure the project explorer to display the working set as the root element in the tree rather than the project.
I've just spent the last hour looking at threads on Stackoverflow.com , trying to import a Maven project in to Spring ToolSuite 2.5.2.
The Maven project has multiple modules, when I use the Import... wizard in STS to import the project All the Modules are listed in the Package Explorer and some of the modules dependencies are not resolved.
Can any advise on the proper way to import a Multi-Module Maven project in to STS/Eclipse such that all the modules appear under a Parent directory?
And so all the modules dependencies are resolved?
The project is in a hierarchy on the file system,
I've tried the various Update Dependencies, Project Configuration options but all to no avail.
I have an embedded version of Maven installed in the IDE.
Thanks for your time.
M2Eclipse does a very good job at resolving inter-project dependencies. If it doesn't work, perhaps your project structure has errors. Check that:
every child project references the correct version of the parent project
every dependency has the version that corresponds to the current project version in the workspace
every child project is registered as a <module> in the parent pom (profile must be active if the module is defined in a profile).
If these versions don't match, the artifacts referenced will be pulled from the local repository, not the eclipse workspace.
About common root projects: I don't think it's a good idea to have a common Project, but the Eclipse concept that comes to mind (and that I use for multi-module projects) is a Working Set.
In the Package Explorer, switch the Top Level Elements to Working Sets:
Now choose Configure Working Sets ... from the same menu.
Here's a working set with the maven3 trunk and all submodules as separate projects:
Ugly trick - but sometimes can help:
mvn clean eclipse:clean eclipse:eclipse
Import projects as usual Eclipse project
enable Maven's Dependency Management
Perform Update Project Configuration for all modules