I have a weird (?) problem with an EJB I want to deploy to my Glassfish 3.1 application server.
I have this bean, which should be executed continuously in Glassfish using the @Schedule
annotation. This worked fine for me until I added some code to the EJB accessing a database.
@Stateless
public class MyBean implements MyBeanLocal {
@Schedule(second = "*", minute = "*", hour = "*")
public void initiateProcess() {
MyCoordinator mc = new MyCoordinatorImpl();
List<Entity> entities = mc.methodAccessingDB();
}
}
This is my EJB, which is executed every second. How I said above, I can deploy this EJB and it executed successfully, if I don't call ac.methodAccessingDB()
.
This means, that I ca开发者_开发问答n't even deploy it to Glassfish. Glassfish tells me
Invalid ejb 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.. Please see server.log for more details.
If I just write List<Entity> entities = null;
instead of List<Entity> entities = ac.methodAccessingDB();
I can deploy it and it runs fine.
OK, now I have found the solution for this problem. The EJB couldn't find the classes on the deployed version. The solution was to pack everything into an ear project. I am using maven, so I created in the end 3 projects.
- one for the EJB
<packaging>ejb</packaging>
- one for the EAR
<packaging>ear</packaging>
- and a third parent project, which integrates the both other projects as
<module>
.
I then deployed the packed ear to Glassfish and the timer started and everything was there.
精彩评论