0

I am trying to create a connection using connectionFactory.createConnection() method but it returns a null.

Below is my code :

     @Stateless

     public class test

    {
 @Resource(mappedName = "java:comp/DefaultJMSConnectionFactory")     
 private static ConnectionFactory connectionFactory;  
@Resource(mappedName = "jdbc/JurassicParkCon")   
private static Queue queue; 

public static void main(String args[])
{
     Connection connection = null;      
     Session session = null;       
     MessageProducer messageProducer = null;  
     TextMessage message = null;       
     final int NUM_MSGS = 3; 

   try {  
       connection = connectionFactory.createConnection();
       }
       catch(Exception e){System.out.println("It is:"+e.getMessage());}

In the above code am only trying to create a connection but it returns NullPointerException. I have added a JMS resource through the admin console in GlassFish (name is jdbc/JurassicParkCon).

Recently only I started working with EJB's so I am not very familiar with errors. I have added the @Stateless annotation because there was a similar problem which was posted on StackOverflow and for that user adding the annotation worked but not for me.

What might be the problem here ?

Thank you for your time.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Troller
  • 1,108
  • 8
  • 29
  • 47

1 Answers1

0

It won't work as a standalone application. You need to run it in a container.

ACV
  • 9,964
  • 5
  • 76
  • 81