简体   繁体   English

无法在独立客户端上实例化initialcontext

[英]Cannot instantiate initialcontext on standalone client

I have a standalone client that I do not want to deploy on my Glassfish server. 我有一个不想在我的Glassfish服务器上部署的独立客户端。 With the client I want to post message via the Point to Point communication pattern. 我想与客户通过点对点通信模式发布消息。 I found this great tutorial, which uses annotations I cannot use because I have a standalone client. 我找到了这个很棒的教程,它使用了我无法使用的注释,因为我有一个独立的客户端。 I found the following solution on stackoverflow: 我在stackoverflow上找到了以下解决方案:

Context jndiContext;
private ConnectionFactory connectionFactory;
private static Queue queue;

public TweetSender() throws NamingException{
    jndiContext = new InitialContext();
    connectionFactory = (ConnectionFactory) jndiContext.lookup("JMS/KwetterConnectionFactory");
    queue = (Queue) jndiContext.lookup("JMS/KwetterQueue");
}

I also found out that I had to import some libraries from the glassfish directory. 我还发现我必须从glassfish目录中导入一些库。 So I did: 所以我做了: 项目性质

I get the following error: 我收到以下错误:

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.SerialInitContextFactory]

What am I doing wrong? 我究竟做错了什么?

EDIT 编辑

I found a temporary solution for the problem though I feel it's not the right one (I think I might get problems when I want to migrate the project. I removed the libraries which I retrieved from the Glassfish lib folder and added them using the "Absolute path". 我找到了解决该问题的一种临时解决方案,尽管我认为这不是正确的解决方案(我想在迁移项目时可能会遇到问题。我删除了从Glassfish lib文件夹中检索到的库,并使用“绝对”路径”。

A solution can be packing your standalone client application in a jar file, eg: myclient.jar. 一种解决方案是将独立的客户端应用程序打包到jar文件中,例如:myclient.jar。 And run it as an application client using appclient utility of GlassFish: 并使用GlassFish的appclient实用程序将其作为应用程序客户端运行:

applcient -client myclient.jar

The appclient utility can be found here: [glassfish home dir]/glassfish/bin. 可以在以下位置找到appclient实用程序:[glassfish主页目录] / glassfish / bin。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM