Deploying multiple Web Slice projects within an EAR without a WAR

I have several JJB or EJB modules that also include their web resources as described in this question .

Now I would like to deploy this as part of the EAR.

Now I could do it like a war without any problems, and this is my backup plan. However, I would like to understand whether it is possible to deploy several โ€œweb fragmentโ€ banners in the ear to form a complete web application without having a war file there to combine all this.

In addition, if I have several military files that depend on one or more of these cans, I will have to build them so that these banks are duplicated in the WEB-INF / lib of military files, even if the military files then end in one ear ?

In this case, if jar files include entities, will they also be needed at the root of the ear so that a global persistence block can be defined?

I am on JBoss 7, although I would prefer a standard container independent solution if possible.

+4
source share
1 answer

This will work on any JEE5 compatible server.

Suppose you have

  • 2 EJBs called myejb1.jar and myejb2.jar
  • 2 WAR web applications called mywebapp1.war and mywebapp2.war
  • 2 regular JARs called log4j.jar and mycommon.jar

You want to pack all this into an EAR file called myapp.ear.

The directory structure myapp.ear will look like this:

myapp.ear:
META-INF / application.xml
myejb1.jar
myejb2.jar
mywebapp1.war
mywebapp2.war
lib / log4j.jar
lib / mycommon.jar

The contents of your META-INF / application.xml file will contain

<?xml version="1.0" encoding="UTF-8"?> <application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"> <module> <ejb>myejb1.jar</ejb> </module> <module> <ejb>myejb2.jar</ejb> </module> <module> <web> <web-uri>mywebapp1.war</web-uri> <context-root>webapp1</context-root> </web> </module> <module> <web> <web-uri>mywebapp2.war</web-uri> <context-root>webapp2</context-root> </web> </module> <library-directory>lib</library-directory> </application> 

You will be able to access your web applications via URL
http: //myJBossServer.url/webapp1/
http: //myJBossServer.url/webapp2/

You can also share static resources such as CSS, images, JavaScript among several webapps. For example, I have a static-content.jar file with this directory layout:

static-content.jar:
META-INF / resources / css / my.css
META-INF / resources / img / my.jpg
META-INF / resources / js / jQuery.js
META-INF / resources / js / node.js

I put static-content.jar in the WEB-INF / lib directory on both of my web pages at build time. Now

http: //myJBossServer.url/webapp1/css/my.css
http: //myJBossServer.url/webapp2/css/my.css

have the same source from static-content.jar.

If I wanted to override the default my.css only in webapp2, I can put the changed my.css in mywebapp2.war directly.

mywebapp2.war
css / my.css
WEB-INF / lib / static-content.jar

css / my.css in WAR will override my.css from static-content.jar

+2
source

All Articles