Esper deployment on jboss as 7.X, event type or class name not found - java-ee-6

I have developed a java ee project to be deployed on jboss as 7 server.
scenario is
A java ee project in which ejb module contains execution classes.
some of the pojo events are defined in another plain java project lets say p1
and p1 is referenced in java ejb module and it appears in ./lib directory
of ear where other jar files exists.
auto-import tag in esper-config.xml has been added for p1 classes.
"cepConfig.cnfigure(esper-config.xml)" executes fine and
I can see all event types as reuired in debug mode.
"EpServiceProvider.getProvider("MyEngine",cepConfig)" results in error
which says "could not find event type or class named p1.mypack.class1"
I have checked reference and deployment settings of projects. p1.jar exists in ./lib directory.
All classes are public and accessible. what other things i need to check?

That class "p1.mypack.class1" would need to be part of the classpath, either the Jboss system classpath or the module classpath.

Related

How to deploy two cross-dependent EARs in JBoss 7 in order to prevent ClassCastExceptions?

I have a problem when deploying two ear files in Jboss 7 and would be thankful for your help.
Following scenario:
EAR 1 contains EJBs which are looked up by EAR 2 (also) at server startup. Thus, EAR 1 has to be deployed before EAR 2 (via jboss-deployment-structure.xml dependency settings).
Right after being deployed, EAR 1 also needs access to classes contained in EAR 2 because of Hibernate and JNDI related class loading (among others).
But as EAR 2 isn't deployed at that time, there's a need for EAR 1 to contain a client-jar file of EAR 2.
Now, the problem is that in the course of EAR 1 and EAR 2 configuration (at server startup) ClassCastExceptions occur because...
(non-EJB) Java object obj1, whose class C was loaded by the classloader of EAR 1, is bound in JNDI
and after being looked up, supposed to be cast to object obj2 whose class C was loaded by the classloader of EAR 2
Now I wonder, if there's a possibility that these common classes of EAR 1 and EAR 2 are being loaded with the same classloader in JBoss 7. I already tried to put them in a server module, which didn't work out.
Thanks a lot for your help in advance!
PS: I'm aware of the poor design declared above. But due to restrictions, I have to follow up on it.
To avoid class cast exceptions, the common libraries need to be put in a classloader that is common to all applications in the two EARs, and no other copies of those libraries should exist in each application.
If it's an option to use only one EAR instead of two, put all the WARs inside a single EAR, remove the common classes from the WARs and put them on the EAR library folder.
This will associate the common classes to the EAR classloader, which is common to all the applications running inside a EAR, so that would solve the problem.
If you must use two EARS, then the common classes need to be put in a classloader at the level of the server shared by all applications.
JBoss 7 is an OSGI based container that allows to create an isolated module with a few jars and link it to an application. So if you try this:
create a module with the common library AND it's dependencies, see instructions here
link the module to all applications
remove the copies of those libraries from all applications and leave them only at the module
It will work fine, but don't forget to put the dependencies of the common library in the module as well otherwise it will not work, the dependencies need to be visible at the level of the module, and there can be no duplicate jars between module and applications (otherwise class cast exceptions might happen).
Another way far less recommendable but it would also work, is to put the common classes at the level of the common classloader, see this diagram. The common classloader folder is located at $CATALINA_HOME/lib (Jboss is based internally on Tomcat).
Specially if there are other applications running in that server don't try the second option. It could help to have a look at a tool I built for these type of issues, JHades.

Make a deployable Java EE project from a java project

I have coded a small Java EE project that consists only of EJBs, helper classes and their tests.
The project is a maven project and creates a jar.
Right now, all tests are happening with JUnit and JMockit.
Now I want to deploy my application to a local glassfish 4.
What do I have to do, to deploy the project? I know that normaly a root Project with a root-Pom is created, that holds a EAR Project with the ear-Pom and the EJB Project with the ejb-jar.
I checked out the jee-simple-archetype, which was - for my kind of project - much to sophisticated and not simple at all. Could somebody explain how I package and deploy my app correctly?
I know that normaly a root Project with a root-Pom is created, that holds a EAR Project with the ear-Pom and the EJB Project with the ejb-jar
This is not necessarily the "normal" way. You can deploy a .jar containing EJBs on its own. Typically you would do this if the EJB beans are either called remotely (via RMI/#Remote or via SOAP/#WebService) or if the application contains some job-like logic (#Singleton/#Startup, or maybe JSR 352 Batching).
Could somebody explain how I package and deploy my app correctly?
In your pom.xml you should use <packaging>ejb</packaging>, that's basically it (assuming you have an otherwise valid pom.xml). The resulting jar can be deployed on its own. For GlassFish you would use the asadmin deploy command for this.

JBOSS AS 7 custom class loader not working

We recently moved to JBOSS AS 7.Since it is based on OSGi and all modules are isolated, we are having a problem.
One of our jars is loaded by a URLclassloader from a specified directory outside of the JBOSS modules.
Class[] parameters = new Class[]{URL.class};
URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class;
Method method = sysclass.getDeclaredMethod("addURL",parameters);
method.setAccessible(true);
method.invoke(sysloader,new Object[]{ flist[i].toURI().toURL()});
flist[i] contains the jar with complete path to be loaded.
Where as this used to work previously, after AS 7, this class is not getting loaded.
I know you can add these jars to the modules folder and specify dependency. But we want this to work.
Is there a solution for this?
As others have said, JBoss AS 7 is not based on OSGi, it uses its own module system (JBoss Modules). What you're doing (reflection on classloaders) is against any rules, totally unsupported and worked only by accident. You you should is the following:
create a JBoss module for your JAR (the link is for a database module but should work with any JAR)
use jboss-deployment-structure.xml to reference that module

JBoss eap 6 (as 7) - 2 different classes with same package and name

I am having an issue with a 3rd party developer.
They have provided a number of jars, and unfortunately in 2 different jars they have different implementations of a class (same name, same package).
We deploy using a single war file where both jars (among many others) are packaged together in web-inf/lib directory and unfortunately both jars are needed.
Is there a way where I can guarantee in JBoss eap 6 that the class from a.jar gets loaded before the class from b.jar?
Thanks.
All of your answers about classloading on JBoss can be found here at this link. But since now I advise you to read the "JBoss Deployment Structure File" section
With the "jboss-deployment-structure.xml" JBoss specific deployment descriptor you can control class loading in a fine grained manner. It should be placed in the top level deployment, in META-INF (or WEB-INF for web deployments). It can do the following:
Prevent automatic dependencies from being added
Add additional dependencies
Define additional modules
Change an EAR deployments isolated class loading behaviour
Add additional resource roots to a module

Glassfish V3.1 Invalid ejb jar it contains zero ejb

I'm just about migrating from JBoss 6.1 to Glassfish 3.1 (don't ask why). The following occurs:
Invalid ejb jar [mmsUserMgmtAct-0.0.1-SNAPSHOT.jar]: it contains zero ejb
...
Note:
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-
driven bean.
2. EJB3+ entity beans (#Entity) are POJOs and please package them as library jar.
3. If the jar file contains valid EJBs which are annotated with EJB component level
annotations (#Stateless, #Stateful, #MessageDriven, #Singleton), please check server.log
to see whether the annotations were processed properly.
As everything was running perfectly with Jboss I can swear there are EJBs within the jars. The only thing which might cause the error is the fact, that I splitted the interfaces (#Remote and #Local) plus the entities (#Entity) into a package xyzService.jar and the stateless bean (#Stateless, #Remote(XyzService.class)) into another archive named xyzServiceImpl.jar.
All packaging was generated by maven, so no issues with this. Maybe I should mention that I simply copied the things into autodeploy folder.
Any glues?
Thx in advance
El Subcomandante