Archetype for EJB + JBoss7 Porj
Categories:
Setting Up a JBoss 7 EJB Project with Maven Archetype

Learn how to quickly bootstrap an Enterprise JavaBeans (EJB) project for JBoss 7 using Maven archetypes, streamlining your development workflow.
Developing Enterprise JavaBeans (EJB) applications for JBoss 7 (WildFly) can be significantly simplified by leveraging Maven archetypes. An archetype is a Maven project templating toolkit that allows users to create new projects from a predefined pattern. This article guides you through the process of generating, configuring, and deploying a basic EJB project using a suitable Maven archetype, specifically focusing on JBoss 7 compatibility.
Understanding Maven Archetypes for EJB Projects
Maven archetypes provide a standardized way to create new projects. For EJB development, an archetype typically sets up the basic project structure, pom.xml
dependencies for EJB APIs, JBoss-specific configurations, and a sample EJB and client. This saves considerable time compared to manually setting up a project, ensuring best practices and correct dependencies are in place from the start. While many archetypes exist, selecting one that aligns with JBoss 7 (WildFly) and EJB 3.x specifications is crucial.
flowchart TD A[Start] --> B{Choose Archetype} B --> C[Generate Project] C --> D[Configure pom.xml] D --> E[Develop EJB] E --> F[Build Project] F --> G[Deploy to JBoss 7] G --> H[Test Application] H --> I[End]
Typical EJB Project Development Workflow with Maven Archetype
Generating the EJB Project Archetype
The first step is to use Maven to generate the project from an archetype. We'll use a common archetype that provides a good starting point for EJB 3.1 projects compatible with JBoss AS 7 / WildFly. Open your terminal or command prompt and execute the following Maven command. This command will prompt you for groupId
, artifactId
, version
, and package
.
mvn archetype:generate \
-DarchetypeGroupId=org.codehaus.mojo.archetypes \
-DarchetypeArtifactId=ejb-javaee6 \
-DarchetypeVersion=1.0 \
-DgroupId=com.example \
-DartifactId=my-ejb-project \
-Dversion=1.0.0-SNAPSHOT \
-Dpackage=com.example.ejb \
-DinteractiveMode=false
Maven command to generate an EJB 3.1 project archetype.
-DinteractiveMode=false
flag allows you to run the command non-interactively, using the provided -D
parameters. If you omit it, Maven will prompt you for each value.Project Structure and Initial Configuration
After generation, you'll have a new directory named my-ejb-project
(or whatever you set as artifactId
). Inside, you'll find a standard Maven project structure, including a pom.xml
file, src/main/java
for your EJB source code, and src/test/java
for tests. The pom.xml
will already contain the necessary dependencies for EJB 3.1 and Java EE 6. You might need to adjust the JBoss-specific dependencies or plugin versions to align perfectly with your JBoss 7/WildFly version.
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-ejb-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<version.jboss.bom>7.0.0.Final</version.jboss.bom> <!-- Adjust as needed -->
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Other dependencies like CDI, JPA if needed -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<!-- JBoss specific plugins for deployment if desired -->
</plugins>
</build>
</project>
Example pom.xml
snippet for an EJB project, highlighting key configurations.
jboss-javaee-6.0
BOM version is appropriate. For WildFly, you might use wildfly-javaee7
or wildfly-javaee8
BOMs depending on your WildFly version and desired Java EE specification.Developing and Deploying Your EJB
With the project set up, you can now start developing your EJBs. The archetype usually provides a sample StatelessSessionBean
and its remote/local interfaces. You can modify these or add new ones. Once your EJB is developed, you can build the project into an EJB JAR and deploy it to your running JBoss 7 (WildFly) instance.
1. Navigate to Project Directory
Open your terminal and change the directory to your newly created project: cd my-ejb-project
.
2. Build the EJB JAR
Compile and package your EJB project into a .jar
file using Maven: mvn clean install
. This will create the EJB JAR in the target/
directory.
3. Deploy to JBoss 7/WildFly
Manually copy the generated EJB JAR (e.g., my-ejb-project-1.0.0-SNAPSHOT.jar
) from the target/
directory to the standalone/deployments/
folder of your JBoss 7/WildFly installation. JBoss will automatically detect and deploy the EJB.
4. Verify Deployment
Check the JBoss server logs for successful deployment messages. You should see output indicating that your EJB has been registered and is available.