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 :
there is already a project deployed on Koala (true, it was deployed together with the ear)
or (when I change the build-version) it doesn't "know" the ejbs and I get a number of ClassNotFound Exceptions.
Is there a way to deploy the modules of the application one by one?
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.
Related
I'm trying to deploy .EAR on Liferay (running on JBoss), I put .EAR to JBoss deployments folder. My structure is:
lib (some libraries/modules)
META-INF
WAR (it contains all Liferay specific libraries from auto deploy)
JAR
According to console, deploy is correct. JAR is running (I have some methods with Timers and they are working properly). But I don't see any portlets from WAR that I can add, but according to console WAR is deployed. They are simply not exposed to Liferay. I know that the .EAR is like a closed structure.
I am wondering how to make portlets available to Liferay?
I would appreciate any ideas, thank you.
Currently there is no standard way to deploy portlets (WAR) inside EAR. Liferay won't detect them. Your WAR with portlets must be deployed separately.
I have a WAR file which contains some web application.
I have created a new java web application and i want to use some classes of the WAR which i already have.
How to add the WAR file as a dependency in my new Java Web Application in using eclipse.
I am running this application in Tomcat 7.0 server.
Thanks & Regards,
Rahul
A WAR file is not intended as a dependency, it has a structure specifically designed for deployment to application servers (that understand that structure).
I would move the classes you want to depend on into a separate jar and then have both the war project and your new project depend on it.
You could also create a client jar from the war project which your new application could depend on. However, if you go down the maven route, the Sonatype tutorial will say that each maven project should only produce one artifact.
i'm setting up a new multi module project structure. for now there is an ejb and an ear module and i want to add a web module for a RESTful web service. what is the best approach?
the application looks like this (modules and their content):
app (pom): the parent pom
core (ejb): ejb, hibernate, DAOs, entities, business logic
ear (ear): the module that creates a deployable container
now i would like to add a restful webservice module.
looking at the jboss-as-7 quickstart applications from http://www.jboss.org/jbossas/downloads there is always a war module which just bootstraps the rest service while the beans with jax-rs annotations are part of the ejb project (in my case core:
app
ejb (containing services + beans with jax-rs annotations)
ear
war (just containing a web.xml)
my issue with this approach is that the ejb module contains the services and the rest resources. wouldn't it be better to keep them separate? or is this the way to go?
otherwise: which approach would be better?
app
core
ear
rest (war which contains the rest resource beans and the web.xml)
or
app
core
ear
rest
rest-resources (separate container for the rest resource beans)
rest-war (war which only contains the web.xml)
From a JEE6/JAX-RS point of view the only thing you need a WAR file for is to actually have something to hand off to the application server to deploy. It can literally contain no resources (except for the ones required to make it a valid archive) and your application will still work as long as your classes are made available somewhere on the classpath. So, its really up to you to bundle up these classes as you see fit.
The one thing you will need is a class that extends javax.ws.rs.core.Application. This class is used as a marker/bootstrap to indicate to the application server that there are REST resources available in the web archive that need to be loaded. In most shops I've seen this class placed in the WAR project itself.
If you are really looking for organizational tips, I would recommend you start off by grouping all the REST resource classes together in their own project. Add as dependencies, any projects that are required for the resource classes to work (for example your core and ear projects). Add all three (rest, ear, core) as dependencies for your war project.
Then refine the model as needed, as you work your way through implementation.
There is a really awesome JBoss Maven Archetype for this sort of project.
1) Go to eclipse with maven integration installed
2) New -> Project -> Maven Project
3) Click Next
4) In Filter type in ee6
5) Out of the options that appear, use Group ID: "org.jboss.spec.archetypes", and Artifact ID: "jboss-javaee6-webapp-archetype"
6) Out will come a beautifully structured web application project with EAR connecting to a EJB project and a WAR project.
I have an Enterprise project with an EJB module and a Web module.
I am trying to deploy these modules separately on Glassfish server (local) on my machine.
If I right click and deploy these projects from Netbeans, they get deployed and run good.
But if I try to deploy them from the Glassfish AminConsole,
the ejb module gets deployed successfully without any problem.
but the web module deployment fails.
The ClassDefinitionNotFoundException is thrown for all the EJBs in the ejb module.
But the ejb module jar is in the war file (in the WEB-INF/lib folder).
I am using Netbeans7.0 and Glassfish 3.1.
What's the right way to handle this problem?
Thank you.
It was actually the Netbeans that did not include the ejb-jar inside my war when build the application as ear. And the fix was to build them (jar and war) individually.
We currently run two separate webapps (WARs) deployed in one single EAR containing additional JARs and settings. To improve our deployment I want to split one of these webapps into different modules that may be build and packaged individually. But I've currently no clue on how to package these modules so that I'm able to add or remove them as desired - at best during runtime.
The webapp is getting more and more complex and I'd like to separate some of the functionality into modules. These modules should be packaged as single archives. As long as they contain only classes and resources loaded through code I know how to do this (simple JARs). But how about JSPs? Normally a WAR file contains JSPs or HTML files. I my case it are JSF pages utilizing JBoss Seam and RichFaces.
These modules will add classes, resources and JSF pages and other includes to the running webapplication. Is it somehow possible to deploy them as individual archives to serve the same running webapp?
We are using Maven for our build and packaging and deploy into JBoss v4.
Simple way of doing it is to put the JSPs of different modules in different folders and the JSPs which are used commonly in all modules can be kept in the root.
Now if you want to unload a module, remove the corresponding folder.
Hope this helps.