Title: Juggling Java EE with Enterprise Apache Maven
1Juggling Java EE with Enterprise Apache Maven
- Jesse McConnell - jmcconnell_at_apache.org
2Who Am I?
- On Maven PMC
- Active in Continuum
- Some maven plugins
- Some mojo plugins _at_ codehaus
- axistools-maven-plugin - dont hold that against
mepls - Redback _at_ codehaus
3Is this you?
4Java EE Application Development by Convention
- No laughing matter
- People cry everyday because of java ee
- Maven can help keep crying to a minimum
- hopefully
- Planning is key
5Components of Java EE
- Enterprise Java Beanss
- maven-ejb-plugin
- V. 2 and 3 specs
- Web Services
- axistools-maven-plugin
- cxf-maven-plugin
- others
- Web Archives (Wars)
- maven-war-plugin
- Enterprise Archives (Ears)
- maven-ear-plugin
6You should end up with
7Maven Lifecycle
- Supported since the beginning with maven 2
- Java EE artifact linkage is managed through
dependencies - Artifact construction dictated by lttype/gt
8Understanding Structure in Maven
- Follow Conventions
- Archiva and Continuum are good example Web
Applications - Redback is security overlay packaged as a Web
Application and overlaid
9Library Code
- Understanding the final goal and scoping
dependencies appropriately. - That meansunderstand Java EE classloaders
- Understand your Container
- Like to think they are all interchangeable
- Can be harder in practice
10EJB Structure and Management
- ltpackaginggtejblt/packaginggt
- Directory Layout
-- pom.xml -- src -- main --
resources -- META-INF
-- ejb-jar.xml
11EJB Structure and Management
- Plugin Example
- ltplugingt
- ltartifactIdgtmaven-ejb-pluginlt/artifactIdgt
- ltconfigurationgt
- ltgenerateClientgttruelt/generateClientgt
- lt/configurationgt
- lt/plugingt
12Linking into Build
- Validates ejb-jar.xml file existence
- Unless you specify ejbVersion 3.0
13Testing EJB Code
- Best bet is testing modularly like with normal
junit testing. - Otherwise test when in ear and under typical ejb
conditions
14Web Service Structures and Management
- No strict lifecycle phase
- No strict directory layout
- Depends on web service architecture in use
- xfire -gt CXF, Axis, etc
- Code generation components
- wsdl2java
- java2wsdl
15Linking into Build
- Consider services, clients, resource libraries
- Common project layout
- Annotations of services
- All kind of implementation specific
- Real deal is testing them
16Testing Web Services
- Can be hard to test directly
- Client testing against established servers begs
irreproducibility - Test by deploying services to embedded jetty and
running client code
17War Structure and Management
- ltpackaginggtwarlt/packaginggt
- Directory Layout
- -- pom.xml
- -- src
- -- main
- -- java
- -- com
- -- example
- -- projects
- -- SampleAction.java
- -- resources
- -- images
- -- sampleimage.jpg
- -- sampleresource
- -- webapp
- -- WEB-INF
- -- web.xml
- -- index.jsp
- -- jsp
18War Structure and Management
- Plugin Example
- ltplugingt
- ltgroupIdgtorg.apache.maven.pluginslt/groupIdgt
- ltartifactIdgtmaven-war-pluginlt/artifactIdgt
- ltversiongt2.0lt/versiongt
- ltconfigurationgt
- ltwebappDirectorygt/container/deploy/dirlt/w
ebappDirectorygt - lt/configurationgt
- lt/plugingt
19War Overlay
- Often handy to build component oriented wars.
- Overlay multiple war files to create actual war
file. - Continuum and Archiva do this is redback for
shared security and user management bits
20Linking into Build
- Dependency management scoping is key
- Dig into your war file and see what is in there
- Dont be afraid, its doesnt bite
- ltscopegtprovidedlt/scopegt can be your friend
- Other Options
- ltwarSourceExcludesgtWEB-INF/lib/.jarlt/warSourceExc
ludesgt
21Three different usages
- Warwar - standard war creation
- Warexploded - builds out war in exploded format
in target dir - Warinplace - builds out webapp in
src/main/webapp - Dependency Management scoping key for war
usability
22War Overlay I - Clean
- ltplugingt
- ltgroupIdgtorg.apache.maven.pluginslt/groupId
gt - ltartifactIdgtmaven-clean-pluginlt/artifactId
gt - ltversiongt2.1.1lt/versiongt
- lt!-- This configuration is added to
cleanup from warinplace --gt - ltconfigurationgt
- ltfilesetsgt
- ltfilesetgt
- ltdirectorygtbasedir/src/main/webap
plt/directorygt - ltincludesgt
- ltincludegtimages/redbacklt/includegt
- lt!-- Images from other wars --gt
- ltincludegttemplate/lt/includegt
- lt!-- validation.js --gt
- ltincludegttemplate/redbacklt/include
gt - lt!-- Templates from other wars
--gt - ltincludegtWEB-INF/classeslt/includegt
- lt!-- Classes and Resources from
other wars --gt - ltincludegtWEB-INF/liblt/includegt
23War Overlay II - War
- ltplugingt
- ltgroupIdgtorg.apache.maven.pluginslt/groupId
gt - ltartifactIdgtmaven-war-pluginlt/artifactIdgt
- ltversiongt2.0.1lt/versiongt
- ltconfigurationgt
- ltarchiveClassesgtfalselt/archiveClassesgt
- ltdependentWarExcludesgtMETA-INF/,WEB-IN
F/web.xml,WEB-INF/classes/xwork.xml,WEB-INF/lib/
- lt/dependentWarExcludesgt
- lt/configurationgt
- ltexecutionsgt
- ltexecutiongt
- ltphasegtcompilelt/phasegt
- ltgoalsgt
- lt!-- Needed to get the
plexus-security war overlay to do its thing
before jettyrun --gt - ltgoalgtinplacelt/goalgt
- lt/goalsgt
- lt/executiongt
- lt/executionsgt
- lt/plugingt
24Jetty Configuration
- ltplugingt
- ltgroupIdgtorg.mortbay.jettylt/groupIdgt
- ltartifactIdgtmaven-jetty-pluginlt/artifactId
gt - ltversiongt6.1.0lt/versiongt
- ltconfigurationgt
- ltscanIntervalSecondsgt10lt/scanIntervalSec
ondsgt - ltcontextPathgt/lt/contextPathgt
- ltjettyEnvXmlgtbasedir/src/jetty-env.xm
llt/jettyEnvXmlgt - ltconnectorsgt
- ltconnector implementation"org.mortbay
.jetty.nio.SelectChannelConnector"gt - ltportgt9090lt/portgt
- ltmaxIdleTimegt60000lt/maxIdleTimegt
- lt/connectorgt
- lt/connectorsgt
- lt/configurationgt
- ltdependenciesgt
- ltdependencygt
- ltgroupIdgtorg.apache.derbylt/groupIdgt
- ltartifactIdgtderbylt/artifactIdgt
ltsystemPropertiesgt
ltsystemPropertygt ltnamegtappserver.bas
elt/namegt ltvaluegtproject.build.dire
ctory/appserver-baselt/valuegt
lt/systemPropertygt ltsystemPropertygt
ltnamegtappserver.homelt/namegt
ltvaluegtproject.build.directory/appserver-hom
elt/valuegt lt/systemPropertygt
ltsystemPropertygt
ltnamegtderby.system.homelt/namegt
ltvaluegtproject.build.directory/appserver-base/l
ogslt/valuegt lt/systemPropertygt
lt/systemPropertiesgt
25Testing Wars I
- jetty-maven-plugin for click testing
- mvn jettyrun
- Integration testing a bit more involved
26TestingWars II
- generate-resources
- dependency-maven-plugin
- Unzip the webapp
- Prepare provided dependencies
- package
- maven-antrun-plugin
- Copy container configuration
- Copy provided dependencies
- pre-integration-test
- selenium-maven-plugin
- Start server
- cargo-maven2-plugin
- Start container
- integration-test
- maven-antrun-plugin
- Check continuum started
- maven-surefire-plugin
- Run tests
- Post-integration-test
27Scoping War Dependencies
- Two Approaches, different scoping
- Deploying Wars
- Integrating into Ears
28Ear Structure and Management
- Directory Layout
- No specific directories required
- Dependencies are key to ear files
- Automatic application.xml creation
- MANIFEST.MF Creation
29Ear Structure and Management
- Plugin Example
- ltplugingt
- ltartifactIdgtmaven-ear-pluginlt/artifact
Idgt - ltconfigurationgt
- ltarchivegt
- ltmanifestgt
- ltaddClasspathgttruelt/addClassp
athgt - lt/manifestgt
- lt/archivegt
- lt/configurationgt
- lt/plugingt
30Linking into Build
- Just do it
- Then triage.
- Primary recommendation, keep your project modular
- Test your modules
- Use ear module as simply the aggregation of the
project - packaging
31Supported Ear Modules
- ejb3Module - ejb3 (Enterprise Java Bean version
3) - ejbClientModule - ejb-client (Enterprise Java
Bean Client) - ejbModule - ejb (Enterprise Java Bean)
- jarModule - jar (Java Archive)
- harModule - har (Hibernate Archive)
- parModule - par (Plexus Archive)
- rarModule - rar (Resource Adapter Archive)
- sarModule - sar (JBoss Service Archive)
- webModule - war (Web Application Archive)
- wsrModule - wsr (JBoss Web Service Archive)
32Testing Ears
- Functionally the same kind of process as the war
integration testing - use cargo
- Bind start app server to pre-integration-test
phase - Start Selenium server
- Run any surefire tests
- Bind stop app server to post-integration-test
33Scoping Ear Dependencies
- Learn Dependency Management in parent poms
- Love it
- Plan for ear deployment, scope things that are
used by multiple war and ejbs as provided or
test in those poms - Scope for inclusion in ear, leave versioning to
the dependencyManagement, its why it is there
34Application Deployment Options
- Cargo - cargo.codehaus.org
- Supported containers
- Geronimo 1.x - geronimo1x
- JBoss 3.x, 4.x - jboss3x, jboss4x
- Jetty 4.x, 5.x, 6.x - jetty4x, jetty5x, jetty6x
- jo! 1.x - jo1x
- OC4J 9.x - oc4j9x
- Orion 1.x, 2.x - orion1x, orion2x
- Resin 2.x, 3.x - resin2x, resin3x
- Tomcat 3.x, 4.x, 5.x - tomcat3x, tomcat4x,
tomcat5x - WebLogic 8.x - weblogic8x
- Maven2 plugin support
- Deployment area largely untargeted by maven
conventions - Hard to standardize in real world
35Tips and Tricks
- Got a 300meg ear file?
- Check the scoping
- Pull apart the artifacts and look for jar
duplication - Understand Java EE classloaders
36Tips and Tricks II
ltprofilesgt ltprofilegt ltidgtprodlt/idgt
ltpropertiesgt ltejb.jdbc.urlgtjdbcodbcprod
UIDprodPWDp4ssw0rdlt/ejb.jdbc.urlgt
ltserver.typegtprodlt/server.typegt
lt/propertiesgt lt/profilegt ltprofilegt
ltidgttestlt/idgt ltpropertiesgt
ltejb.jdbc.urlgtjdbcodbctestUIDtestPWDp4ssw0rd
lt/ejb.jdbc.urlgt ltserver.typegttestlt/server.
typegt lt/propertiesgt lt/profilegt
ltprofilegt ltidgtdevlt/idgt ltpropertiesgt
ltejb.jdbc.urlgtjdbcderbydevlt/ejb.jdbc.urlgt
ltserver.typegtdevlt/server.typegt
lt/propertiesgt lt/profilegt lt/profilesgt
- ltbuildgt
- ltpluginsgt
- ltplugingt
- ltartifactIdgtmaven-ejb-pluginlt/artifactIdgt
- ltconfigurationgt
- ltejbVersiongt3.0lt/ejbVersiongt
- ltclassifiergtserver.typelt/classifiergt
- lt/configurationgt
- lt/plugingt
- lt/pluginsgt
- lt/buildgt
37Using Archetypes
- maven-archetype-j2ee-simple
- Sample aggregate project
- Geronimo sample archetypes
- Many jetty sample archetypes
- http//www.webtide.com/resources.jsp
38Questions?
- Jesse McConnell - jmcconnell_at_apache.org
- Resources
- Better Builds with Maven
- Maven The Definitive Guide