【发布时间】:2014-07-19 18:15:04
【问题描述】:
我有一个像下面这样的课程:
public class Poligon {
public static void main(String[] args) {
try {
Context ctx = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("jms/javaee7/ConnectionFactory");
Destination destination = (Destination) ctx.lookup("jms/javaee7/Topic");
JMSContext context = connectionFactory.createContext();
OrderDTO order = context.createConsumer(destination).receiveBody(OrderDTO.class);
System.out.println("Order received: " + order);
} catch (NamingException ex) {
Logger.getLogger(Poligon.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
我想从在 localhost 上运行的服务器 (glassfish) 中获取 InitialContext(),但出现以下错误:
SEVERE: null
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:
java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at poligon.Poligon.main(Poligon.java:29)
我知道我必须在 glassfish 上创建 ldap 领域并将以下代码(? - 不知道确切的值)添加到我的班级:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"?");
env.put(Context.PROVIDER_URL, "?");
env.put(Context.SECURITY_PRINCIPAL, "?");
env.put(Context.SECURITY_CREDENTIALS, "?");
Context ctx = new InitialContext(env);
我的问题是我不知道应该在什么值:
Context.INITIAL_CONTEXT_FACTORY
Context.PROVIDER_URL (I want it on localhost)
Context.SECURITY_PRINCIPAL
Context.SECURITY_CREDENTIALS
我不知道应该如何配置 glassfish 服务器?
maven 依赖
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.appclient.client</groupId>
<artifactId>gf-client</artifactId>
<version>3.1.2.2</version>
</dependency>
【问题讨论】:
-
为清晰起见修正问题
-
你能告诉我哪一部分不清楚吗?
-
问题是:“如何在我的客户端应用程序中使用位于 glassfish 服务器上的可用资源?”?
标签: java glassfish initial-context