Singleton EJB not found - maven

I've an EAR with an EJB and WAR project in it. I use Netbeans and the Maven building tool. In my EJB there is one EJB, a singleton class: http://pastebin.com/f8jXw0TK
Here is a screenshot of my project structure in Netbeans: https://gyazo.com/09e075972279f637de2d4d98fe9a1ac7
When I deploy the EAR or the EJB-JAR in Glassfish (localhost). I get the follow error message:
Error occurred during deployment: Exception while deploying the app [arp-auth-business-1.0] : Invalid ejb jar [arp-auth-business-1.0]: 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.. Please see server.log for more details.
I've added a simple stateless bean to the EJB JAR, and then it deployed. But then I saw just the simple stateless bean I created, but not my singleton class.
What could be wrong? The server.log shows the same error I get in Glassfish but with a exception stack from the loader. No error from the singleton class or something like that...
Still trying but can't figure it out. Maybe it's maven? But the jar and war file are in the ear file. And in the jar file there is my singleton class.
Kind regards

Related

Can spring hibernate project be attached as jar in another maven project

I have a spring-hibernate-springboot project deploying as WAR. I need to use it as jar in another JAVA project. I have seperated its controller part and now made changes in maven to deploy it as jar. I am able to attached it to another project and can call service method. But I have autowired Dao into that service file; when any method of dao is called null pointer exception is thrown. It means Dao is not getting autowired.
Any help will be appriciated.

Classloader issue on Mule server

I am running my application on mule server. Mule server has there own sets of jars and my application that is running on mule server also has few jars. While working on Spring batch I found that JettisonMappedXmlDriver class exists in my application xstream jar as well as mule server jar as well. This class internally refer MappedXMLOutputFactory class that is in jettision jar which is also in my application but some how I am getting classnotfound error for MappedXMLOutputFactory class. This looks like class-loader issue.
If I add jettision jar in mule server then everything work fine but, I can't add this jar on my production environment. Can some body tell me how do I force to load the class from my application jettision jar file. It looks weird to me as classloader should have load MappedXMLOutputFactory class from jettision jar that is in my application folder like it is doing for other classes.
Please let me know if anybody found such issue.
The Mule application classloader is configurable: http://www.mulesoft.org/documentation/display/current/Classloader+Control+in+Mule
So just configure your application's classloader to first look at the JARs it embeds in /lib before deferring to the Mule System classloader.
You will encounter this issue if you have multiple versions of the same class in differnet jars, albeit with different method signatures. The ClassNotFound Error is usually not the only exception that occurs, you will often see another one before that, typically a "NoSuchMethodException" which forces class loader to unload the offending class.
I would suggest using maven or gradle to assemble your application and then use the dependency:tree target to query version conflicts.

Maven EAR project won't register Faces Converter

My Maven EAR project has two WAR module and one EJB module. There is a FacesConverter class in EJB module and when I try to use it from one of the WAR module it throws an exception. I register this converter with annotation #FacesConverter("org.util.ObjectConverter") use it in a JSF page
javax.servlet.ServletException: Expression Error: Named Object: org.util.ObjectConverter not found.
When ObjectConverter is in WAR module it works fine, but it won't load from the EJB module.
What am I missing here?
Cheers
Why do you put it in EJB module? Front-end (read: JSF) artifacts should go in WAR module. EJB module should only contain business services which are supposed to be reuseable to front-ends other than JSF, such as JSP/Servlet, Struts2, SpringMVC, JAX-RS, etc. The EJB module should absolutely have no single line of javax.faces.* import/dependency in the code.
JSF doesn't look for converters (let alone any other JSF related artifacts such as validators, managed beans and Facelets files) in EJB module, but only in WAR module. Just keep them in the WAR module. Whatever code you think need to share between the WAR and EJB modules should be refactored into a separate Java project which end up as a common JAR file in EAR module (note that this should in turn also contain no JSF-specific artifacts.

multiple EJB jar file inside one EAR sharing the same persistence.xml

I am using JBoss 4.2.3 application server.
I have an EAR that currently contains 2 EJB (EJB 3) jars.
In the main EJB jar I have persistence.xml file with the data source configurations.
From the secondary EJB jar file I can successfully call the the EntityManager and read\write entities that are defined in the main EJB jar that contains the persistence.xml
If I try to put an entity in the secondary EJB jar module and then persist it via the EntityManager that uses the persistence unit from the main EJB I get an exception:
Caused by: org.hibernate.hql.ast.QuerySyntaxException: [ENTITY-CLASS-NAME] is not mapped
The solution I found is to create another persistence.xml in the secondary EJB module and change the persistence unit name.
I am not sure whether what I tried to do is correct? Can you please contribute whether I can have a way to share the same persistence.xml withing multiple EJB modules in the EAR (in a way I can have entities in both EJB modules)?
Put the persistence.xml and entities into a JAR in the top-level lib/ directory of the EAR. This should allow the persistence units to be used by all modules in the EAR.

Ejb refrences another ejb

I have two EJBs , EJB A references EJB B, both are deployed to the same server.
Each time I try to deploy EJB A it tries to register EJB B which is already deployed and registered which causes error:
java.lang.IllegalStateException
Any idea how to prevent EJB A from registering the referenced EJB?
I am using NetBeans and JBoss 4.2.3 as well as EJB 3.0.
If you use maven build
you can use
<scope> provided </scope>
in the pom file of maven of EJB A
Although I cannot imagine why you get an exception if your EJB A is singleton try the annotation #DependsOn on A to specify a dependency on B.

Resources