GameDroids
GameDroids

Reputation: 5662

deploying WAR and EJB-jar files separately

I have an application which I am deploying on GlassFish. It has an EJB-tier with (JPA) Entites and EJBs to get access and write to the database and it has 3 (independent) web apps. Everything is built with Maven.

ServerApplication 
  |
  +-ServerApplication-ear
  +-ServerApplication-ejb
  |
  +-GrumpyCat (war)
  +-HummingBird (war)
  +-Koala (war)

All three war projects depend on the ejb project. When compiling/building the ear, it copies the war files to the ear project and then I can deploy the ear file on GlassFish.

This works fine, all 4 modules (the ejb, and the 3 war) get deployed without problems and I can access the 3 war projects like:

myServer.com/GrumpyCat
myServer.com/HummingBird
myServer.com/Koala

My problem is, that I can't deploy a single war project on its own. For example when I change something in the koala project, I would like to be able to build only the koala.war and deploy it on the server, without having to upload and deploy the complete ear file.

But when deploying, GlassFish tells me either :

Is there a way to deploy the modules of the application one by one?

Upvotes: 0

Views: 834

Answers (1)

Alexander Langer
Alexander Langer

Reputation: 2903

Your second approach is the way to go if you really want to deploy them individually. However, you are seeing a ClassNotFound exception because the WARs are individual projects and as such don't have access to the EAR's class path.

To make that work, you have to add the public API of your application to your WAR's classpath. The public API consists of at least the EJB's remote interfaces of the EJBS that you would like to access from the WAR and any DTOs used in your API.

The easiest way is to create a separate package (such as com.example.api) and let a build tools such as ant or Maven bundle that api package together with your EJBs and your WARs, or you create a myapp-api.jar and include it in the respective class-paths.

Then you can remove the WARs from the EAR and deploy them as separate projects.

Upvotes: 1

Related Questions