I am just switching from Ant to Maven and am trying to figure out the best practice to set up a EAR file based Enterprise project?
Let's say I want to create a pretty standard project with a jar file for the EJBs, a WAR file for the Web tier and the encapsulating EAR file, with the corresponding deployment descriptors.
How would I go about it? Create the project with archetypeArtifactId=maven-archetype-webapp
as with a war file, and extend from there? What is the best project structure (and POM file example) for this? Where do you stick the ear file related deployment descriptors, etc?
Thanks for any help.
What helped me a lot was to run the Maven archetype:generate goal and select from one of the archetypes, some of which seem to be updated regularly (in particular JBoss seems to be well maintained).
Hundreds of archetypes appeared in a numbered list from which to select (519 as of now!). The goal, still running, prompted me to make a selection by entering a number or entering a search string e.g.:
I entered the search string "ear," which reduced the list to only 8 items (as of today):
I selected "org.jboss.spec.archetypes:jboss-javaee6-ear-webapp" (by entering the selection "5" in this example).
Next, the goal asked me to enter the groupId, artifactId, package names, etc., and it then generated the following well-documented example application:
After reading the four POM files, which were well-commented, I had pretty much all the information I needed.
You create a new project. The new project is your EAR assembly project which contains your two dependencies for your EJB project and your WAR project.
So you actually have three maven projects here. One EJB. One WAR. One EAR that pulls the two parts together and creates the ear.
Deployment descriptors can be generated by maven, or placed inside the resources directory in the EAR project structure.
The maven-ear-plugin is what you use to configure it, and the documentation is good, but not quite clear if you're still figuring out how maven works in general.
So as an example you might do something like this:
NetBeans IDE automatically defines the structure which is almost similar to one suggested by Patrick Garner. For NetBeans users
File->New Project ->In left side select Maven and In right side select Maven Enterprise Application and press Next -> Asks for project names for both war,ejb and settings.
The IDE will automatically create the structure for you.
I've been searching high and low for an end-to-end example of a complete maven-based ear-packaged application and finally stumbled upon this. The instructions say to select option 2 when running through the CLI but for your purposes, use option 1.
This is a good example of the maven-ear-plugin part.
You can also check the maven archetypes that are available as an example. If you just runt mvn archetype:generate you'll get a list of available archetypes. One of them is
i have made a github repository to show what i think is a good (or best practices) startup project structure...
https://github.com/StefanHeimberg/stackoverflow-1134894
some keywords:
Maven Output: