javascript javax.naming.NamingException:从类加载器实例化 InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13065025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 17:45:23  来源:igfitidea点击:

javax.naming.NamingException: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader

javajavascriptweb-servicesjbossjboss7.x

提问by vivek rai

I have s problem with Jboss-as-7.1.1. when I deploy it, it deploys properly, but when I send the request from client side I am getting this error:

我对 Jboss-as-7.1.1 有问题。当我部署它时,它会正确部署,但是当我从客户端发送请求时,我收到此错误:

javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory

javax.naming.NamingException: JBAS011843: 实例化 InitialContextFactory 失败

MyErrorlog:-

我的错误日志:-

14:18:22,952 INFO  [stdout] (http--127.0.0.1-8080-1) BusinessClass::sendResponse Starts...
14:18:22,953 INFO  [stdout] (http--127.0.0.1-8080-1) Enter the Try Block Edited by vivek
14:18:22,962 ERROR [stderr] (http--127.0.0.1-8080-1) javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "deployment.responsecomponent.ear.response.war:main" from Service Module Loader
14:18:22,978 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)
14:18:22,996 ERROR [stderr] (http--127.0.0.1-8080-1)    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:664)
14:18:22,998 ERROR [stderr] (http--127.0.0.1-8080-1)    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
14:18:23,007 ERROR [stderr] (http--127.0.0.1-8080-1)    at javax.naming.InitialContext.init(InitialContext.java:223)
14:18:23,008 ERROR [stderr] (http--127.0.0.1-8080-1)    at javax.naming.InitialContext.<init>(InitialContext.java:197)
14:18:23,010 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.jsp.response_jsp._jspService(response_jsp.java:132)
14:18:23,011 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
14:18:23,012 ERROR [stderr] (http--127.0.0.1-8080-1)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
14:18:23,014 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
14:18:23,037 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
14:18:23,038 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
14:18:23,040 ERROR [stderr] (http--127.0.0.1-8080-1)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
14:18:23,041 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
14:18:23,049 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
14:18:23,051 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
14:18:23,053 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
14:18:23,054 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
14:18:23,064 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
14:18:23,065 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
14:18:23,066 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
14:18:23,068 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
14:18:23,069 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
14:18:23,076 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
14:18:23,078 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
14:18:23,081 ERROR [stderr] (http--127.0.0.1-8080-1)    at java.lang.Thread.run(Thread.java:662)

ServerLog:-

服务器日志:-

JBoss Bootstrap Environment

  JBOSS_HOME: /home/vivekray/Desktop/vivek/jboss-as-7.1.1.Final

  JAVA: /home/vivekray/Softwares/jdk1.6.0_30/bin/java

  JAVA_OPTS:  -server -XX:+TieredCompilation -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Djboss.server.default.config=standalone.xml

=========================================================================

14:14:09,212 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA
14:14:09,978 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA
14:14:10,233 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
14:14:13,122 INFO  [org.xnio] XNIO Version 3.0.3.GA
14:14:13,148 INFO  [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
14:14:13,224 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
14:14:13,264 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
14:14:13,553 INFO  [org.jboss.as.clustering.infinispan] JBAS010280: Activating Infinispan subsystem.
14:14:13,557 INFO  [org.jboss.as.configadmin] JBAS016200: Activating ConfigAdmin Subsystem
14:14:13,619 INFO  [org.jboss.as.naming] JBAS011800: Activating Naming Subsystem
14:14:13,660 INFO  [org.jboss.as.osgi] JBAS011940: Activating OSGi Subsystem
14:14:13,707 INFO  [org.jboss.as.security] JBAS013101: Activating Security Subsystem
14:14:13,765 INFO  [org.jboss.as.webservices] JBAS015537: Activating WebServices Extension
14:14:13,809 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
14:14:14,204 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-4) JBAS015400: Bound mail session [java:jboss/mail/Default]
14:14:14,260 INFO  [org.jboss.as.connector] (MSC service thread 1-3) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
14:14:14,514 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
14:14:14,773 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-2) JBoss Web Services - Stack CXF Server 4.0.2.GA
14:14:15,739 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-4) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
14:14:16,378 WARN  [com.arjuna.ats.arjuna] (Transaction Expired Entry Monitor) ARJUNA012210: Unable to use InetAddress.getLocalHost() to resolve address.
14:14:16,636 INFO  [org.jboss.as.remoting] (MSC service thread 1-3) JBAS017100: Listening on /127.0.0.1:9999
14:14:16,639 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on /127.0.0.1:4447
14:14:16,717 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-3) JBAS015012: Started FileSystemDeploymentService for directory /home/vivekray/Desktop/vivek/jboss-as-7.1.1.Final/standalone/deployments
14:14:17,095 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
14:14:17,201 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "responsecomponent.ear"
14:14:24,491 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry jaxb-api.jar in "/content/responsecomponent.ear/lib/jaxb-xjc-2.1.7.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,502 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry jaxb-impl.jar in "/content/responsecomponent.ear/lib/jaxb-xjc-2.1.7.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,515 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry jsr173_1.0_api.jar in "/content/responsecomponent.ear/lib/jaxb-xjc-2.1.7.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,524 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry activation.jar in "/content/responsecomponent.ear/lib/jaxb-xjc-2.1.7.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,539 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry jaxb-api.jar in "/content/responsecomponent.ear/lib/jaxb-impl-2.1.7.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,548 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry activation.jar in "/content/responsecomponent.ear/lib/jaxb-impl-2.1.7.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,564 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry jsr173_1.0_api.jar in "/content/responsecomponent.ear/lib/jaxb-impl-2.1.7.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,567 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry jaxb1-impl.jar in "/content/responsecomponent.ear/lib/jaxb-impl-2.1.7.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,575 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry bcel.jar in "/content/responsecomponent.ear/lib/jibx-bind-1.2.1.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,580 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry jibx-run.jar in "/content/responsecomponent.ear/lib/jibx-bind-1.2.1.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,583 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry xpp3.jar in "/content/responsecomponent.ear/lib/jibx-bind-1.2.1.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,585 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry stax-api.jar in "/content/responsecomponent.ear/lib/jibx-bind-1.2.1.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,589 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry wstx-asl.jar in "/content/responsecomponent.ear/lib/jibx-bind-1.2.1.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,594 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry xercesImpl.jar in "/content/responsecomponent.ear/lib/xalan-2.7.0.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,596 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry xml-apis.jar in "/content/responsecomponent.ear/lib/xalan-2.7.0.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,599 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry serializer.jar in "/content/responsecomponent.ear/lib/xalan-2.7.0.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,602 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry activation.jar in "/content/responsecomponent.ear/lib/mail-1.4.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,613 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry xpp3.jar in "/content/responsecomponent.ear/lib/jibx-run-1.2.1.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,615 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry stax-api.jar in "/content/responsecomponent.ear/lib/jibx-run-1.2.1.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,617 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) Class Path entry wstx-asl.jar in "/content/responsecomponent.ear/lib/jibx-run-1.2.1.jar"  does not point to a valid jar for a Class-Path reference.
14:14:24,630 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "response.war"
14:14:24,633 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "AsyncResponseComponentVer2.jar"
14:14:25,750 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named SPConnectorResponseComponent in deployment unit subdeployment "AsyncResponseComponentVer2.jar" of deployment "responsecomponent.ear" are as follows:

    java:global/responsecomponent/AsyncResponseComponentVer2/SPConnectorResponseComponent!com.cdac.AsyncSPResponse.SPResponseEJBRemote
    java:app/AsyncResponseComponentVer2/SPConnectorResponseComponent!com.cdac.AsyncSPResponse.SPResponseEJBRemote
    java:module/SPConnectorResponseComponent!com.cdac.AsyncSPResponse.SPResponseEJBRemote
    java:jboss/exported/responsecomponent/AsyncResponseComponentVer2/SPConnectorResponseComponent!com.cdac.AsyncSPResponse.SPResponseEJBRemote
    java:global/responsecomponent/AsyncResponseComponentVer2/SPConnectorResponseComponent!com.cdac.AsyncSPResponse.SPResponseEJBHome
    java:app/AsyncResponseComponentVer2/SPConnectorResponseComponent!com.cdac.AsyncSPResponse.SPResponseEJBHome
    java:module/SPConnectorResponseComponent!com.cdac.AsyncSPResponse.SPResponseEJBHome
    java:jboss/exported/responsecomponent/AsyncResponseComponentVer2/SPConnectorResponseComponent!com.cdac.AsyncSPResponse.SPResponseEJBHome

14:14:26,794 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /response
14:14:26,797 INFO  [org.jboss.as] (MSC service thread 1-3) JBAS015951: Admin console listening on http://127.0.0.1:9990
14:14:26,807 INFO  [org.jboss.as] (MSC service thread 1-3) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 18387ms - Started 222 of 303 services (80 services are passive or on-demand)
14:14:26,958 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "responsecomponent.ear"

MyCode:-

我的代码:-

 Context context=null;
    System.out.println("BusinessClass::sendResponse Starts...");
    HashMap ack_gateway=null;
    try {

        System.out.println("Enter the Try Block Edited by vivek");

        //add by vivek

            Properties props = new Properties();
                    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                    props.put(Context.PROVIDER_URL, "remote://localhost:4447");
                    props.put(Context.SECURITY_PRINCIPAL, "testuser");
                    props.put(Context.SECURITY_CREDENTIALS, "testpassword");
                    context = new InitialContext(props);
                System.out.println("\n\tGot initial Context: "+context);
                System.out.println("Got Initial Context");
              SPResponseEJBHome home = (SPResponseEJBHome)  ortableRemoteObject.narrow(context.lookup            ("SPConnectorResponseComponent"),SPResponseEJBHome.class);

        System.out.println("BusinessClass::sendResponse Starts...");

        System.out.println("Got Home object");
        SPResponseEJBRemote remote = home.create();
        System.out.println("Got Remote object");

Any one have some idea please help me ? Thanks vivek

任何人有一些想法请帮助我?谢谢维维克

回答by Daniele Vrut

I spent a day following tutorials and ebooks (and forum solutions too) for JBoss 6. The main "problem" is JBoss 7 has a different approach for JNDI settings and with InitialContext.

我花了一天时间学习 JBoss 6 的教程和电子书(以及论坛解决方案)。主要的“问题”是 JBoss 7 对 JNDI 设置和 InitialContext 有不同的方法。

Finally I found a tutorial that saved my day, hope this can help you too:

最后我找到了一个拯救我一天的教程,希望这也能帮助你:

http://theopentutorials.com/examples/java-ee/ejb3/how-to-create-a-simple-ejb3-project-in-eclipse-jboss-7-1/

http://theopentutorials.com/examples/java-ee/ejb3/how-to-create-a-simple-ejb3-project-in-eclipse-jboss-7-1/

How I solved

我是怎么解决的

Props must have only this entry:

道具必须只有这个条目:

props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

Missing jboss-ejb-client.propertiesin client folder with this content:

在具有以下内容的客户端文件夹中缺少jboss-ejb-client.properties

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

And jboss-client-7.1.0.Final.jar(JBOSS_HOME/bin/client) missing in build path.

JBoss的客户端- 7.1.0.Final.jar(JBOSS_HOME /斌/客户端)缺少构建路径。

Best regards, Daniele.

最好的问候,丹尼尔。

回答by carlosavoy

first of all, from the server log I see some warnings related to the classpath so that seems to me that is going to jump out some errors later. Maybe you already solved this but the error you report form the client side almost always relate to the classpath you are using to compile that client, for instance, compile it with:

首先,从服务器日志中,我看到了一些与类路径相关的警告,因此在我看来,稍后会跳出一些错误。也许您已经解决了这个问题,但是您从客户端报告的错误几乎总是与您用来编译该客户端的类路径有关,例如,编译它:

javac -cp <JBOSS_FOLDER>/bin/client/jboss_client.jar <your src directory>

greetings

问候

回答by FredFloete

You can use another way to have a lookup for your beans.

您可以使用另一种方式来查找您的 bean。

BeanRemoteInterface bean = doLookup();

doLockup()-Method:

doLockup()-方法:

private static BeanRemoteInterface doLookup() {
Context context = null;
BeanRemoteInterface bean = null;
try {
     // 1. Obtaining Context
    context = ClientUtility.getInitialContext();

    // 2. Generate JNDI Lookup name
    String lookupName = getLookupName();

    // 3. Lookup and cast
    System.out.println("LookUpName: " + lookupName);
    bean = (BeanRemoteInterface) context.lookup(lookupName);
   } catch (NamingException e) {
    e.printStackTrace();
   }
 return bean;
}

getLookupName()-Method:

getLookupName()-方法:

private static String getLookupName() {
/*
 * The app name is the EAR name of the deployed EJB without .ear suffix.
 * Since we haven't deployed the application as a .ear, the app name for
 * us will be an empty string
 */
String appName = "";

/*
 * The module name is the JAR name of the deployed EJB without the .jar
 * suffix.
 */
String moduleName = "PackageName";

/*
 * AS7 allows each deployment to have an (optional) distinct name. This
 * can be an empty string if distinct name is not specified.
 */
String distinctName = "";

// The EJB bean implementation class name
// String beanName = HelloWorldImpl.class.getSimpleName();
String beanName = "NameOfYourBeanImplementation";

// Fully qualified remote interface name
final String interfaceName = BeanRemoteInterdface.class.getName();

// Create a look up string name
String name = "ejb:" + appName + "/" + moduleName + "/" + distinctName
        + "/" + beanName + "!" + interfaceName;

return name;
}

ClientUtility class

客户端实用程序类

  import java.util.Properties;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;

  public class ClientUtility {

   private static final String PROVIDER_URL = "jnp://localhost:1099";
   private static final String JNP_INTERFACES = "org.jboss.naming:org.jnp.interfaces";
   private static final String INITIAL_CONTEXT_FACTORY="org.jnp.interfaces.NamingContextFactory";

   private static Context initialContext;

   public static Context getInitialContext() throws NamingException
   {
    if (initialContext == null) {
        Properties prop = new Properties();
        prop.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
        prop.put(Context.URL_PKG_PREFIXES, JNP_INTERFACES);
        prop.put(Context.PROVIDER_URL, PROVIDER_URL);
        initialContext = new InitialContext(prop);
    }
    return initialContext;
   }
 }