Here is an example that may be useful -> EAR Testing
It is called "EAR Testing", but can be just as easily used to create military files. For the purposes of this answer, I will change the eartesting directory mentioned in the example to wartesting
EAR and WAR files are almost identical, because at the Java EE specification level, we decided to allow war files to contain EJB, CDI beans, etc.
This example uses the Maven build system and has two modules: one for "data objects" and one for "business logic." It seems to fit the way you think about your thoughts and can be a useful starting point. It contains a small sample unit test application for EJB.
You may not have read it yet, but often people refer to EJBs as difficult to test. They are no longer there, and this example shows the latest solution compatible with the specification, so you can kill several birds with one stone, starting from this installation.
What does not include is a module for creating the final WAR file that you will deploy during production. To create this, you simply added a third module
- wartesting / business model
- wartesting / business logic
- wartesting / business-war (added)
In busines-war you will have pom.xml as shown below:
<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/maven-v4_0_0.xsd"> <parent> <groupId>org.superbiz</groupId> <artifactId>myear</artifactId> <version>1.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>business-war</artifactId> <packaging>war</packaging> <dependencies> <dependency> <groupId>org.superbiz</groupId> <artifactId>business-model</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.superbiz</groupId> <artifactId>business-logic</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.apache.openejb</groupId> <artifactId>javaee-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
Then create the following directories:
- wartesting / business war / SRC / home / Java
- wartesting / business war / src / home / web application
And we say, for example, you add the following files to them:
- wartesting / business war / SRC / home / Java / org / superbiz / Foo.java
- wartesting / business war / SRC / home / web application / WEB-INF / web.xml
- wartesting / business war / src / home / web application / index.html
After creating you should get a war file under wartesting/business-war/target/ containing:
WEB-INF/web.xmlWEB-INF/classes/org/superbiz/Foo.classWEB-INF/lib/business-model-1.1-SNAPSHOT.jarindex.html