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.
Related
I'm new to quarkus and what I'm trying to do is I've two JAX-RS application codebase .
I want to package code of both the app as single distribution package.
I want to package it as quarkus app.
To be more clear below is an example for the same .
App1 :(Can be Quarkus app or just JAX-RS war )
Contains Resources-> /rest/greetings
App2 :(Can be Quarkus app or just JAX-RS war )
Contains Resources-> /rest/hello
App3 :(Quarkus app which will be distributed)
Contains Resources-> /rest/greetings
/rest/hello
Uses App1 and App2 as jar or war dependancy
Basically I want to maintain separate codebase for two apps(you can say modules) and third app which is for packaging and distribution.
Idea behind this is to build app with configurable module like in future if I have 5 modules and I just want to build and deliver app with 3 module I can do it .
I'm using gradle as build tool.
Found a solution that worked for me,
Added org.jboss.jandex plugin to my App1 and App2 so it generated jandex index and added both the app as dependency to my App3 so quarkus was able to load these annotated classes on start-up.
Doc for more info here
I have a application which contains the following
some server side logic which are bundled as a jboss module
The EJB layer which is bundle into the EAR
The RESTful layer which is bundled as a war which is in the EAR
Both the EJB and RESTful modules depends on the server side logic modules which are jboss modules. This server side logic has dependencies to other modules such as guava, hibernate, and some home grown modules as well.
Now i want to use Arquillian to write some tests to both EJB and REST layers. But to do that i cannot find any reference how i can include the jboss modules i have in the ShrinkWrap.
I tried searching for documentation but i couldn't find any reference. I only found ShrinkWrap Descriptor library for jboss modules, but not how to ShrinkWrap a complete jboss module with the required jar files.
It would be great if someone point me to a documentation or sample which shows how to ShrinkWrap a complete jboss module.
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.
I have an EJB project which contains a Rest Web Service EJB. I package this EJB.jar project into an EAR file along with a WAR project. What would be the absolute path of my Rest Web Service then?
My problem seems to be due to the fact that the EJB JAR file containing the EJB REST Web Service is packaged in an EAR file alongside a WAR file. I've read that you can use JAX-RS within an EJB JAR file but what I wasn't aware of was that this JAR file has to then be packaged within the WEB-INF/lib folder in a Dynamic Web Project (WAR file). According to this link, it is not supported for JAX-RS EJB's to be included in an EAR file.
Glad that you've already found an answer.
From my perspective, exposing stateless EJB beans as restfull services is fast, but typically isn't the best approach.
Usually, it is better to create restfull endpoint classes in a web module that wraps errors/ exceptions coming from ejb services. This is also a good place to do some translations etc.
I have a Maven web project (Java) that I created in Eclipse. Due to in house IDE restriction I had to move the project to JDeveloper 12c and disable the Maven nature. I had to make several tweaks to project's properties in JDeveloper to make it work.
We found that the back-end code (Service Impl, DAO and Entity classes) can be used on several other projects so we are evaluating/considering to separate the single large web project into 2 projects. One for the front end, which is specific for each project and the other for backend, which is common for all projects.
Here are few ways I thought it can done.
1) From the single large web project, create 2 projects; web UI project and web back-end project.
2) Keep the code as it is and use maven modules or maven overlays feature and generate 2 wars from the same code.
I have not dealt with the projects depending on others or multi module projects a lot. Do you see any issues with this type of architecture, good or bad!
Please let me know if you have any other suggestions or ran into similar situations before. Thanks in advance.
Splitting project into many subproject is a good idea. You could use maven multimodule project setup (docs). Every frontend project would have a separate maven project (module in parent pom) and you'll have one project (module) for the backend.
Depending on your requirements you could then create:
an EAR archive with backend in EJB jar and all frontends in WAR archives,
a WAR archive for every frontend project with EJB jar (or jar for non-plain-javaee setup) inside WEB-INF/lib.
Multimodule setup has few advantages and the main one is that you can build the whole application from scratch just by issuing single mvn command.