2016-04-07 3 views
2

среда используется:ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory

  • WildFly 9.0.2.Final
  • EJB 3.0
  • Ant
  • Затмение

Test.jsp ссылается getDbConnection метод Test.java класс.

test.jsp

<%@page import="com.testmodule.pojo.Test"%> 
<% 
    try{ 
     System.out.println(" Going to call getDbConnection method of 'Test' class. This 'Test' class shall be " 
      + " part of testclient.jar. testclient.jar shall be deployed as a module --- module add --name=testclient --resources=/Downloads/lib/test/testclient.jar"); 
     System.out.println(" test.jsp shall be present in test.ear...'jboss-deployment-structure.xml' shall be present in " 
      + " in META-INF directory of test.ear with entry as -- <dependencies><module name=\"testclient\" export=\"true\" /> </dependencies>"); 
     System.out.println(" Dont want to put 'jboss-client.jar' in Test.ear-->Test.war-->WEB-INF/lib , As there are multiple ear's which are accessing Test.java class"); 

     new Test().getDbConnection(); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 
%> 

Test.java

package com.testmodule.pojo; 

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

public class Test { 
    public void getDbConnection(){ 
     try { 
      Properties jndiProps = new Properties(); 

      jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, 
       "org.jboss.naming.remote.client.InitialContextFactory"); 
      jndiProps.put(Context.PROVIDER_URL,"remote://29.86.30.73:4447"); 
      jndiProps.put(Context.SECURITY_PRINCIPAL, "testuser"); 
      jndiProps.put(Context.SECURITY_CREDENTIALS, "testpassword"); 
      jndiProps.put("jboss.naming.client.ejb.context", true); 

      Context context = new InitialContext(jndiProps); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

После ошибки при доступе к test.jsp.

10:09:26,536 ERROR [stderr] (default task-1) javax.naming.NamingException: WFLYNAM0027: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "deployment.test.ear.test.war:main" from Service Module Loader [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory from [Module "deployment.test.ear.test.war:main" from Service Module Loader]] 
10:09:26,537 ERROR [stderr] (default task-1) at org.jboss.as.naming.InitialContext.getDefaultInitCtx(InitialContext.java:118) 
10:09:26,537 ERROR [stderr] (default task-1) at org.jboss.as.naming.InitialContext.init(InitialContext.java:99) 
10:09:26,537 ERROR [stderr] (default task-1) at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:154) 
10:09:26,537 ERROR [stderr] (default task-1) at org.jboss.as.naming.InitialContext.<init>(InitialContext.java:89) 
10:09:26,548 ERROR [stderr] (default task-1) Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory from [Module "deployment.test.ear.test.war:main" from Service Module Loader] 
10:09:26,548 ERROR [stderr] (default task-1) at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205) 
10:09:26,548 ERROR [stderr] (default task-1) at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455) 
10:09:26,549 ERROR [stderr] (default task-1) at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404) 
10:09:26,549 ERROR [stderr] (default task-1) at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385) 

Я не хочу, чтобы положить JBoss-Client.jar в Test.ear -> Test.war -> WEB-INF/LIB, так как есть несколько Уши, которые будут получать доступ к Test .java класс.

+1

Я предлагаю вам перенести приложение в инструмент здания, такой как Maven или Gradle. В противном случае, как указано в документации к [WildFly documentation] (https://docs.jboss.org/author/display/WFLY9/JNDI+Reference), * Если вы не используете Maven, затененная банка, содержащая все необходимые классы , может быть найденный в каталоге * bin/client * дистрибутива WildFly. *. Это заставит вас поместить его в каждый из ваших модулей, чего вы не хотите. – aribeiro

ответ

0

Ваш код JNDI предназначен для удаленного вызова, когда вы пытаетесь загрузить некоторый локальный источник данных. Вы можете добавить зависимость от клиентского модуля jboss с файлом jboss-deployment-structure.xml.

Смежные вопросы