How to set up Java EE6 application structure

So, after reading DDD and all the benefits and fame, it looks like Java EE doesn't make it easy for you to do this. I decided to create such a structure:

Domain
Repository
Application
View

However, in the commentary of this response DDD and application layer, it looks like an Application layer, which I thought would be a layer with all services annotated with @Stateful, @WebService, etc., is not the place it really should be . It seems that domain models should have these annotations.

So now the question is: how do people structure their applications? Where do you post different annotations and how do they use each other. Can someone please help me understand how I can structure my java ee 6 web application? Please help and don’t say how I do it in a certain tool or something like that, but where are the actual classes and what are intended for different layers.

I'm upset about where to start and how to organize.

+4
source share
2 answers

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.xml
  • WEB-INF/classes/org/superbiz/Foo.class
  • WEB-INF/lib/business-model-1.1-SNAPSHOT.jar
  • index.html
+2
source

There are no specific rules on how you should structure your application. It would be best to use common sense, as well as observe how others do it.

You can create a simple maven project provided by the welder team to see how you can structure the underlying Java EE application:

 mvn archetype:generate -DarchetypeArtifactId=jboss-javaee6-webapp -DarchetypeGroupId=org.jboss.weld.archetypes -DarchetypeVersion=1.0.1.CR1 -DarchetypeRepository=central 

Of course you will find many other examples on github or java.net

+1
source

Source: https://habr.com/ru/post/1396989/


All Articles