+app.ear
+lib
*.jar libraries that the war's use
+classes
*.properties and other configuration files
+META-INF
application.xml
jbos-app.xml
app.war
app2.war
appn.war
- Invoking class from
lib/*.jar
of enclosed EAR to app.war is now working. - When I deploy, could see two instantiations of singleton classes inside "War"(One from container and other from application).
Can we can access war/WEB-INF/classes
from lib/*.jar
.
Mostly it would be helpful for the websockets integration, as the serverendpoint resides on the war file.
I wanted to fetch the session of websockets and process accordingly.
Reason behind why CDI is opted for the accessing WEB-INF/classes or WEB-INF/lib/*.jar : SPEC says about accessibility of classes
By default this is set to false, which allows the sub-deployments to see classes belonging to other sub-deployments within the .ear.
For example, consider the following .ear deployment:
myapp.ear | |--- web.war | |--- ejb1.jar | |--- ejb2.jar If the ear-subdeployments-isolated is set to false, then the classes in web.war can access classes belonging to ejb1.jar and ejb2.jar. Similarly, classes from ejb1.jar can access classes from ejb2.jar (and vice-versa).
The ear-subdeployments-isolated element value has no effect on the isolated classloader of the .war file(s). i.e. irrespective of whether this flag is set to true or false, the .war within a .ear will have a isolated classloader and other sub-deployments within that .ear will not be able to access classes from that .war. This is as per spec.
Edit 2:
Tried all this stuff through CDI implementation based on the blog of Bruno
https://blogs.oracle.com/brunoborges/entry/integrating_websockets_and_jms_with
Faced issues on deployment of the Complete Ear file
Below class is to fire the event to the war/WEB-INF/classes/
import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;
import javax.inject.Named;
import javax.jms.Message;
import javax.websocket.Session;
import org.springframework.stereotype.Component;
@Component
@Stateless
@Named
public class WebsocketMessenger {
@Inject
@MessageEvent
private Event<Message> events;
public void sendMessageToWebsockets(String rawMessage, Session session){
RawMessageEvent rawMessageEvent = new RawMessageEvent(rawMessage, session);
// events.fire();
}
}
import javax.ejb.Stateless;
import javax.enterprise.event.Observes;
import javax.inject.Named;
@Stateless
@Named
public class RawMessageListener {
public void listenToTheRawMessage(@Observes @MessageEvent RawMessageEvent rawMessageEvent){
System.out.println("Received: " + rawMessageEvent);
}
}
Below is the exception trace:
[org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-8) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2015-03-19 11:08:39,085 WARN [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-8) Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messenger': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: javax.enterprise.event.Event XXXX.HelloMessenger.events; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.enterprise.event.Event] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: javax.enterprise.event.Event XXXX.HelloMessenger.events; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.enterprise.event.Event] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:555) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ... 22 more