Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven JavaEE application with separated frontend and backend

I would like to create a Java EE application with fully separated FrontEnd and BackEnd. I found some tutorials where these two modules were packaged into one EAR file. I could create this, and I could deploy my application to the application server.

For security reasons now I have to separately deploy the FrontEnd (Tomcat) and the BackEnd (Weblogic).

What do I have:

Front:

  1. JSF pages
  2. ManagedBeans

Back:

  1. Sessionbeans with business logic (EJB)
  2. Entity classes.

The communication interface between these two layers would be RMI calls.

The first solution when I had one EAR project with these two modules were working, because my backEnd module pom.xml packaging was jar:

<packaging>jar</packaging>

Thus I could include this built jar to my frontEnd's classpath, and my frontEnd saw the required classes.

Now I tried to create ear from my backEnd because with jar packaging I cannot inculde required libraries to my backend and they're missing in runtime. So i changed backEnd packaging to ear in my pom.xml Ok, but if I have EAR build from backEnd then i cannot include it to my frontEnd classpath and my frontend cannot see required classes from the backEnd.

I'm sorry i'm totally confused about this. Can you give me any advice or a tutorial about what is the proper way to separate these two modules. For example how is it possible to build an EAR and a JAR at the same time with maven?

Thank you so much!

like image 894
solarenqu Avatar asked Mar 02 '18 16:03

solarenqu


2 Answers

Somewhere in your project you should have a module with the EJBs and the according packaging type "ejb". Normally an "ejb-client" artefact is also generated. This can be used as a dependency for the frontend. The frontend should be packaged as a "war", the backend as an "ear".

Have a look at the respective maven plugins (EAR, WAR, EJB):

  • https://maven.apache.org/plugins/maven-ear-plugin/
  • https://maven.apache.org/plugins/maven-war-plugin/
  • https://maven.apache.org/plugins/maven-ejb-plugin/
like image 20
Daniel Avatar answered Oct 23 '22 04:10

Daniel


Try this it may help your question.. http://maven.apache.org/plugins/maven-ear-plugin/examples/skinny-wars.html

In a typical J2EE environment, a WAR is packaged within an EAR for deployment. The WAR can contain all its dependent JARs in WEB-INF/lib but then the EAR can quickly grow very large if there are multiple WARs, due to the presence of duplicate JARs. Instead the J2EE specification allows WARs to reference external JARs packaged within the EAR via the Class-Path setting in their MANIFEST.MF.

like image 60
NKR Avatar answered Oct 23 '22 03:10

NKR