• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • All
  • About
Maven | Create an EAR module (EAR file)
  1. Using the archetype "maven-archetype-quickstart"
  2. pom.xml file (sample)

  1. Using the archetype "maven-archetype-quickstart"
    $ mvn archetype:generate \
      -DarchetypeGroupId=org.apache.maven.archetypes \
      -DarchetypeArtifactId=maven-archetype-quickstart \
      -DarchetypeVersion=1.5 \
      -DgroupId=mtitek.maven.ear.samples \
      -DartifactId=mtitek-maven-ear-samples \
      -Dpackage=mtitek.maven.ear.samples \
      -Dversion=1.0.0-SNAPSHOT \
      -DinteractiveMode=false
    You have to modify the created project to adjust it to an EAR project:

    • In the file « pom.xml », change the « packaging » value to « ear » (if the packaging element is missing, add a new one)
      <packaging>ear</packaging>
    • In the file « pom.xml », add the configs of the plugin "maven-ear-plugin" (see bellow an example of the "pom.xml")

    • Clear the contents of the folder « src/main/ »
      $ rm -rf src/main/*
    • Clear the contents of the folder « src/test/ »
      $ rm -rf src/test/*
    • In the folder « src/main/ », add a new folder « application » (the contents of this folder will be added to the "ear" file of the application)
      $ mkdir src/main/application
    • In the folder « application », you can add the folder « META-INF ».

    • In the folder « application », you can also add other configuration files specific to the application server where the EAR will be deployed.

    $ mvn archetype:generate \
    -DarchetypeGroupId=org.apache.maven.archetypes \
    -DarchetypeArtifactId=maven-archetype-j2ee-simple \
    -DgroupId=mtitek.maven.jee.samples \
    -DartifactId=mtitek-maven-jee-samples \
    -Dversion=1.0.0-SNAPSHOT \
    -DinteractiveMode=false
    -->
  2. pom.xml file (sample)
    <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>mtitek.maven.ear.samples</groupId>
        <artifactId>mtitek-maven-ear-samples</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>ear</packaging>
    
        <dependencies>
            <dependency>
                <groupId>mtitek.maven.jar.samples</groupId>
                <artifactId>mtitek-maven-jar-samples</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <type>jar</type>
            </dependency>
    
            <dependency>
                <groupId>mtitek.maven.war.samples</groupId>
                <artifactId>mtitek-maven-war-samples</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <type>war</type>
            </dependency>
    
            <dependency>
                <groupId>mtitek.maven.ejb.samples</groupId>
                <artifactId>mtitek-maven-ejb-samples</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <type>ejb</type>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>3.3.0</version>
    
                    <configuration>
                        <version>7</version>
                        <defaultLibBundleDir>lib</defaultLibBundleDir>
                        <filtering>true</filtering>
    
                        <modules>
                            <ejbModule>
                                <groupId>mtitek.maven.ejb.samples</groupId>
                                <artifactId>mtitek-maven-ejb-samples</artifactId>
                                <bundleDir>/</bundleDir>
                            </ejbModule>
    
                            <webModule>
                                <groupId>mtitek.maven.war.samples</groupId>
                                <artifactId>mtitek-maven-war-samples</artifactId>
                                <bundleDir>/</bundleDir>
                                <contextRoot>/cr/warPackage</contextRoot>
                            </webModule>
                        </modules>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    Build the project:
    $ mvn clean install
© 2025  mtitek