When running jms examples in eclipse, resource usage does not work.

I want to run jms tutorial files in eclipse. I configured GlassFish correctly and added jms resources. It works fine if I run it in netbeans.

In eclipse, I created a "client application project".

Resources are loaded here:

@Resource(mappedName = "jms/ConnectionFactory") private static ConnectionFactory connectionFactory; @Resource(mappedName = "jms/Queue") private static Queue queue; @Resource(mappedName = "jms/Topic") private static Topic topic; 

Then when he gets here:

 connection = connectionFactory.createConnection(); 

I get a NullPointerException. For some reason, it does not receive resources from the server, so they are zero.

It works if I create a project in eclipse and then run it from the command line using appclient:

  appclient Producer topic 4 

It says http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jst.j2ee.doc.user%2Ftopics%2Fcjappcliproj.html that:

The application client module is used to contain a fully functional client Java ™ application (not a web interface) that connects to Java and uses its EE resources defined on your server. When you place the client code in the client module of the application instead of a simple JAR file, the Benefits of the client application from server resources (it is not necessary to re-specify the class path to Java EE files and the JAR server), as well as from a simpler JNDI search (the client container fills initial context and other parameters).

So it seems like I'm on the right track, but maybe I am missing some eclipse configuration.

+4
source share
1 answer

As you already noticed, if you run the application offline, you will not be able to access the resources of the servers, this is by design. To run the Java EE Client application, you need to use the Glassfish appclient (or similar tools for other application servers). Another thread that can help you set up your project correctly: Eclipse to launch the application client on java ee glassfish appl srv .

+4
source

Source: https://habr.com/ru/post/1382047/


All Articles