开发者

how can i test an EJB using netbeans?

I have been struggling trying to test a super simple EJB project in netbeans. i have tried several examples form my java book, and an even simpler example i found online (http://javadude.wordpress.com/2010/02/22/tutorial-most-simple-test-application-for-embedded-glassfish-netbeans-hudson/). this is a super basic EJB that only just adds two numbers.. that's it!! it runs fine, but no matter how i try to test it, nothing works. even more puzzling, i get two different errors on the two different laptops i test it on. obviously i am doing something very wrong... any advice would be so appreciated.

one error i get is:

Testcase: testAddNumbers(bean.MyBeanTest): Caused an ERROR No EJBContainer provider available: no provider names had been found.

javax.ejb.EJBException: No EJBContainer provider available: no provider names had been found.

and the other is:


SEVERE: Exception while deploying the app java.lang.IllegalArgumentException: Invalid ejb jar [WebTestEmb.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 anno开发者_运维百科tations were processed properly.


clearly, i do have an ejb in my project. it is built exactly as in the directions at the url i posted above.

thanks!


I have been struggling trying to test a super simple EJB project in netbeans. i have tried several examples form my java book, and an even simpler example i found online

Using the EJBContainer API (to start an Embedded EJB container in your testes) is the way to go in Java EE 6 (Adam Bien blogged about this in Embedding EJB 3.1 Container Into Your Unit Tests - Boot Time: 5 Seconds).

That being said, you might be interested by the following links:

  • Yet another Chapter 6 EJB problem
  • Bug 179008 - javax.ejb.EJBException: No EJBContainer provider available: no provider names had been found.
  • Bug 180767 - Embedded EJB container in tests does not work in Maven project

What version of GlassFish are you using? If you're not using the latest 3.0.1, I'd suggest giving it a try.


Never mind, looks like i finally got it working. i cant believe this took a week to figure out!

adding:

Map properties = new HashMap(); properties.put(EJBContainer.MODULES, new File("C:\Documents and Settings\tiv\My Documents\NetBeansProjects\WebTestEmb\build\web\WEB-INF\classes"));

and then using those properties in the createEJBContainer() call fixes the error.


No matter what I write in for the property for EJBContainer.MODULES, it just does not want to work. Also this module workaround is just hacking. I don't think it is supposed to work this way. For the time untill this will be fixed in glassfish, i'll try OpenEJB.

I am a bit disappointed though with glassfish right now. They say everyting works out of the box, and it is just not the case. There are no options to set, and the error messages saying nothing...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜