Deploying ear in tomee - deployment

We are deploying an ear file on Tomee server. We have placed the ear file in tomee/apps folder.
EAR file consists of 1 ejb jar. When we start tomee, deployment is successful without any errors. The ejb has a listener class. How do we tell the EAR to invoke the listener class? Here is my application and web xml but do not see log messages printed from the Listener class. So I know the listener class its not called. Can anyone help? Totally new in this area and migrating from weblogic to tomee. Thanks
myproject/src/main/application/META-INF/application xml
<module>
<ejb>abc-ejb.jar</ejb>
</module>
myproject/src/main/webapps/WEB-INF/web xml
<listener>
<listener-class>com.xyz.listener.startup.AbcListener</listener-class>
</listener>

Related

Wildfly 13 - Proper project setup using logback in an ear project

I am deploying my application as an ear archive in wildfly 13. The ear contains a war and an ejb. The ejb is used in different projects. I want to log the information from the war and the ejb into a single file to have the full context what happend in a single logfile.
I managed to log from the war via logback, but the logs from the ejb are not logged via logback.
My current setup:
In my ear-module I have a jboss-deployment-structure.xml in my ear file to exclude the logging subsystem
In my web-module the logback.xml is located in WEB-INF/classes
In my web-module I have the dependencies to logback-classic and slf4j
In my ejb-module I have a dependency to slf4j
Any suggestions?
If you're just logging to a file you could use a logging-profile which would allow you to make runtime changes and not have to redploy your application if you want to make changes to your logging configuration.
Using WildFly Logging
Example Profile Configuration
/subsystem=logging/logging-profile=ear1:add
/subsystem=logging/logging-profile=ear1/pattern-formatter=PATTERN:add(pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n")
/subsystem=logging/logging-profile=ear1/periodic-rotating-file-handler=FILE:add(append=true, suffix=".yyyy-MM-dd", named-formatter=PATTERN, file={relative-to=jboss.server.log.dir, path="ear1.log"})
/subsystem=logging/logging-profile=ear1/root-logger=ROOT:add(level=INFO, handlers=[FILE])
Then you'd just add Logging-Profile: ear1 entry in your EAR's manifest.
Using Logback
If you want to continue using logback you'd need to put the logback and slf4j dependencies in your EAR/lib directory. The trick will be figuring out where to put the logback configuration file. It might work in EAR/META-INF or in the EAR/lib, but I'm not certain. It may even work if you kept it in the WAR/WEB-INF/classes, but you'd need to ensure a logger is accessed in the WAR before one is accessed in the EJB.
You'll also want to ensure you exclude the org.slf4j.api module or the logging subsystem for the EAR and each subdeloyment in your jboss-deployment-structure.xml.

Not able to access REST within EAR

I am using JBoss to deploy my EAR application which contains a RESTful War file.
I am using javax.was.rs.ApplicationPath, and the REST is accessible and running ok when I deploy the WAR directly on the server.
Problem is when I deploy it within the EAR file, I am not able to access it.
In the application.xml, I have the following
<module>
<web>
<web-uri>TP-Server.war</web-uri>
<context-root>/api</context-root>
</web>
</module>
In the javax.ws.rs.Application:
#ApplicationPath("/")
public class ApplicationConfig extends Application {
}
Is there any special configuration to make REST works in EAR?
Thanks
got problem solved. i think i just tried to republished the app.

Java Web Application deployment on JBoss 7.1

I intend to develop and deploy a simple web application using
EJB 3
JSP and servlet
JBoss 7
JPA
I have coded the application and created a standard ear with following structure
app.ear
|_ lib (with all required jars such as the commons logging)
|_ META-INF
|_ application.xml
|_ jboss-app.xml
|_ app_ejb.jar (contains a stateless EJB, an entity, persistence.xml etc...)
|_ app_web.war (jsps, servlet, web.xml etc..)
jboss-app.xml :- (library is the app name)
<!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD J2EE Application 1.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd">
<jboss-app>
<loader-repository>library:app=ejb3</loader-repository>
</jboss-app>
application.xml :-
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4">
<display-name>library</display-name>
<module>
<ejb>ejb_library.jar</ejb>
</module>
<module>
<web>
<web-uri>web_library.war</web-uri>
<context-root>web_library</context-root>
</web>
</module>
</application>
Now when I deploy this ear with the admin console of JBoss 7, the web module seems to have been deployed, even the pages are hit. However, the further part of the application where I try to inject the EJB in the servlet (as a instance varialbe using #EJB), fails.
There seems to be some problem in the way I am deploying the application.
I tried to find a tutorial where I could deploy the app in JBoss but with all that I am stuck till this.
Could anyone guide me with this? I am using JBoss for the first time and am not completely aware of JBoss specific configurations.
EJB that you are injecting, is it implementing an interface? and is that interface registered with the server? #Local or #Remote.
If not, then Try introducing a #Local interface and then your EJB implementation implementing that interface; and then, use that local interface to inject the EJB implementation.
Also, check the threads below;
JBoss 6: Injecting EJB into servlet
Inject an EJB into JAX-RS (RESTful service)
http://docs.jboss.org/ejb3/docs/tutorial/1.0.0/html/Injecting_EJB_in_Servlets.html
A silly thought, but can you re-arrange the modules declarations in application.xml; bring web modules first and ejb following it.
module -> web module
module -> ejb module
Moreover, this is also related to your situation:
http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/ch01s04s02.html

Who runs the EJB Classes in WAR File

From the Java EE6 documentation, I could see:
To include enterprise bean class files in a WAR module, the class files should be in the WEB-INF/classes directory.
To include a JAR file that contains enterprise beans in a WAR module, add the JAR to the WEB-INF/lib directory of the WAR module.
With this structure, EJBs are part of WAR file. I can have some JSP and Servlet also inside my war file.
I've also read that an Application server contains two containers, one of them is web container that handles all the JSP/Servlets and an app container that handles all the Enterprize beans.
I'm assuming that If I deploy this WAR file (that contains EJB + JSP/Servlets), App-Server will be smart enough to delegate the processing of JSP/Servlets to Web Container and EJBs processing to app containers? Is my assumption correct?
Yes, your assumption in correct.

JBoss 4.0.5 MDB Configuration

This one is beating me, and I have not been able to figure it out ... So here it goes.
I want to add a Message Drive Bean to my app which is packaged as a .ear file
Following the documentation I've created a jboss.xml and a ejb-jar.xml, which I tried to put on the META-INF and the root and on the WEB-INF but I just don;t see it working (i.e. the MDB is never loaded, nor it received the messages.
My ear file looks like:
META-INF/
META-INF/MANIFEST.MF
META-INF/application.xml
myapp.war
My final solution was to separate the MDB code (and supporting classes) into a separate file inside the ear (myapp-mdb.jar) And to support that with the same hibernate mappings and classes, the hibernate related files were packaged on the myapp.har.
META-INF\MANIFEST.MF
META-INF\application.xml
META-INF\jboss-app.xml
myapp-mdb.jar
myapp.har
myapp.war
Just posting the answer for reference.