Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I do It?

 
Higor Zardo
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, I'm trying to do a simple test EJB project in Netbeans 6.5 and Glassfish V2, but It is terrible.

Look... I just do It. First a created a project in New Project -> Java EE -> EJB Module. Ok!
In directory "Source Code Packeages" I created one package called "stateless" with yours two ejb. They are:

package stateless;

import javax.ejb.Stateless;

/**
*
* @author Higor
*/
@Stateless
public class TesteEJBBean implements TesteEJBRemote {

public String getMessage() {
return "Hello EJB World";
}

}


And the Remote:

package stateless;

import javax.ejb.Remote;

/**
*
* @author Higor
*/
@Remote
public interface TesteEJBRemote {

public java.lang.String getMessage();

}

In Enterprise Beans directory it have the same code of TesteEJBBean. I think Netbeans do it automaticaly, I dont remember if I put it there.

Ok,it's work!
But How can I try test it???

I tryed to put a simple java class in "Test Package" directory like it:

package Teste;
import javax.ejb.EJB;
import stateless.TesteEJBRemote;
/**
*
* @author Higor
*/
public class NewClass {
@EJB
private static TesteEJBRemote teste;

public static void main(String[] args) {
//System.out.println(teste.getMessage());
System.out.println("teste");
}
}

The compilation is Ok, but when I select it and select Execute option it have a error.

The compilation step I'm doing with all this classes is: Select the project and right mouse click and select BUILD.
Later I just select NewClass in Test Package directory and try Compile -> Execute.

Anyone can help me please??

Thank you a lot if you can help me!!!
Higor
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Higor,

Sorry for the delay in replying, I just came back from vacation...

Feel free to use the example code for EJB 3 in Action: http://www.manning.com/panda/. The problem is that you will need an application client container (ACC) to use injection inside a command-line class: http://forums.java.net/jive/message.jspa?messageID=177032. Remember, something in your commsn-line app will need to understand the @EJB annotation. Inside a WAR or EAR file, the application servers "sees" the @EJB annotation and performs the injection.

I would just use look-ups in your test client for now. Our JBoss code examples does this since JBoss doesn't have an application client container.

Hope this helps,
Reza
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic