在eclipse中运行jms示例时资源注入不起作用。 [英] Resources injection doesn't work when running jms examples in eclipse.

查看:173
本文介绍了在eclipse中运行jms示例时资源注入不起作用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在eclipse中运行jms教程文件。我已经正确配置了glassfish并添加了jms资源。如果我在NetBeans中运行它,它就可以。



我在eclipse中创建了一个应用程序客户端项目。



  @Resource(mappedName =jms / ConnectionFactory)
private static>

ConnectionFactory connectionFactory;
@Resource(mappedName =jms / Queue)
私有静态队列队列;
@Resource(mappedName =jms / Topic)
private static Topic topic;

然后,当它到达这里时:

  connection = connectionFactory.createConnection(); 

我得到一个NullPointerException。由于某种原因,它不会从服务器获取资源,因此它们为空。



如果我在eclipse中构建项目,然后从命令行运行它使用appclient:

  appclient生产者主题4 

这里说 http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jst.j2ee.doc.user%2Ftopics%2Fcjappcliproj.html
$ b


应用程序客户端模块用于包含全功能客户端
Java™应用程序(非基于Web的),它连接并使用服务器中定义的Java
EE资源。将
中的客户端代码放在应用程序客户端模块而不是简单的JAR文件中时,
应用程序客户端可以从服务器资源中获益(它不需要
来重新指定类路径到Java EE和服务器JAR文件)作为
以及从更简单的JNDI查找(客户端容器填充
的初始上下文和其他参数)中获取。


所以看起来我在正确的轨道上,但也许我错过了一些eclipse配置。

正如你已经注意到的,如果你以独立模式运行你的应用程序,你将无法访问服务器资源,这是设计。您需要使用Glassfish appclient (或其他应用程序服务器的类似工具)才能运行Java EE客户端应用程序。
另一个线程可以帮助你配置你的项目正常运行: eclipse howto在java ee glassfish appl srv上启动应用程序客户端


I want to run the jms tutorial files in eclipse. I have configured glassfish properly and added the jms resources. It works ok if I run it in netbeans.

I created an "application client project" in eclipse.

Here is where the resources get injected:

 @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 it gets here:

connection = connectionFactory.createConnection();

I get a NullPointerException. For some reason it doesn't get the resources from the server so they are null.

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

 appclient Producer topic 4

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

An application client module is used to contain a full-function client Java™ application (non Web-based) that connects to and uses the Java EE resources defined in your server. When you place the client code in an application client module instead of a simple JAR file, the application client benefits from the server's resources (it does not need to re-specify the class path to Java EE and server JAR files) as well as from easier JNDI lookup (the client container fills in the initial context and other parameters).

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

解决方案

As you've already noticed, if you run your Application in standalone mode you will not be able to access servers resources, this is by design. You need to use Glassfish appclient (or similar tools for other application servers) in order to run a Java EE Client App. Heres another thread that may help you configure your project to run correctly: eclipse howto start a application client on java ee glassfish appl srv.

这篇关于在eclipse中运行jms示例时资源注入不起作用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆