A Minimalistic POM For JavaEE 6/7

The essential pom for JavaEE projects is < 40 lines of xml:


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.airhacks</groupId>
    <artifactId>javaee-essentials-pom</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

The war plugin has only has to be added to make web.xml optional :-). If you need a web.xml (for JAX-RS or Servlets web.xml is not needed), you can remove the war plugin as well.

The pom.xml was also checked-in into: https://github.com/AdamBien/javaee-essentials-pom

If you are planning to write tests (:-)), you should replace the javaee-web-api dependency with an actual server implementation.

See you at Java EE Workshops at MUC Airport (Maven is discussed in the "Effective JavaEE" workshop)!


Web Apps, SPA, PWA with vanilla Java Script (ES 6+), CSS 3 and WebStandards only. As simple as possible, but not simpler. See you at: (Progressive) Web apps, Single Page Apps and WebStandards airhacks workshops at MUC airport, Winter Edition

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Comments:

Hello Adam,

Has the crippled APIs problem you mentioned in a previous article (http://www.adam-bien.com/roller/abien/entry/trouble_with_crippled_java_ee) been resolved?

Posted by Gérald on April 28, 2013 at 02:05 PM CEST #

@Gerald,

no. It is going to be resolved in JavaEE 7. For JavaEE 6 you will have to choose an application server. I'm going to add a note to this post.

Thanks for reminding me!,

adam

Posted by Adam Bien on April 28, 2013 at 03:13 PM CEST #

This is for Java EE 6 and will not work for Java EE 7 ?

Posted by Arun Gupta on April 28, 2013 at 07:14 PM CEST #

What would the minimum pom file look like if you need to create an ear file (needed for WebSphere)?

Posted by Craig Doremus on April 29, 2013 at 10:33 PM CEST #

@Arun,

it would work with JavaEE7. However, there is no a Maven JavaEE7 dependency yet deployed to Maven central. You would have to use the dependency from java.net now. I guess it is going to be resolved after JavaEE 7 is finalized.

thanks for the comment,

adam

Posted by Adam Bien on April 30, 2013 at 11:27 PM CEST #

@Craig,

I never used EARs in JavaEE6 projects again. I think the last time I did it in ~2010.

Use NetBeans Maven / Ear wizard or e.g. org.codehaus.mojo.archetypes:ear-javaee6 to get the first idea.

Usually you can delete a lot of stuff afterwards (what I did for WAR projects),

thanks!,

adam

Posted by Adam Bien on April 30, 2013 at 11:30 PM CEST #

To further shorten the POM you could replace the plugin declarations with only the properties:

<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>

Posted by Arend v. Reinersdorff on August 08, 2013 at 12:24 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License