2014-09-13 76 views
0

jndi.properties密鑰的可能屬性名稱是什麼?我找不到關於所有可能的關鍵名稱的文檔。什麼是所有jndi.properties屬性名稱?

如何輸出jndi.properties的主體,憑證和遠程鍵/值對?

-run: 
    [java] Sep 12, 2014 6:36:43 PM dur.bounceme.net.remotelookup.RemoteLookup run 
    [java] INFO: java.naming.factory.initial com.sun.enterprise.naming.impl.SerialInitContextFactory 
    [java] Sep 12, 2014 6:36:43 PM dur.bounceme.net.remotelookup.RemoteLookup run 
    [java] INFO: java.naming.factory.url.pkgs com.sun.enterprise.naming 
    [java] Sep 12, 2014 6:36:43 PM dur.bounceme.net.remotelookup.RemoteLookup run 
    [java] INFO: java.naming.factory.state com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl 

run: 

BUILD SUCCESSFUL 
Total time: 13 seconds 
[email protected]:~/NetBeansProjects/LegacyEJB$ 
[email protected]:~/NetBeansProjects/LegacyEJB$ cat src/java/jndi.properties 
java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory 
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces 
java.naming.provider.url=server.local\:1199 
java.naming.security.principal=user 
java.naming.security.credentials=password 
remote=net.bounceme.ix.Foo 
[email protected]:~/NetBeansProjects/LegacyEJB$ 

可以看出,並不是所有的鍵/值對都被輸出。爲什麼?

對於「遠程」名稱和值,應該在不同的屬性文件中?

主要類:

package dur.bounceme.net.remotelookup; 

import java.util.Enumeration; 
import java.util.Properties; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javax.naming.Context; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 

public class RemoteLookup { 

    private static final Logger log = Logger.getLogger(RemoteLookup.class.getName()); 
    private final MyProps p = new MyProps(); 

    public static void main(String... args) { 
     try { 
      new RemoteLookup().run(); 
     } catch (NamingException ex) { 
      Logger.getLogger(RemoteLookup.class.getName()).log(Level.SEVERE, ex.getExplanation(), ex); 
     } 
    } 

    private void run() throws NamingException { 
     Properties jndi = p.getJNDI(); 
     Enumeration e = jndi.propertyNames(); 
     while (e.hasMoreElements()) { 
      String key = (String) e.nextElement(); 
      String val = jndi.getProperty(key); 
      log.info(key + "\t" + val); 
     } 
     Context ic = new InitialContext(); 
//  MyRemote mr = (MyRemote) ic.lookup("java:comp/env/ejb/Foo"); // 
    } 
} 

讀取屬性文件,在過去的工作:

package dur.bounceme.net.remotelookup; 

import java.io.IOException; 
import java.util.Properties; 
import java.util.logging.Level; 
import java.util.logging.Logger; 

public class MyProps { 

    private static final Logger log = Logger.getLogger(MyProps.class.getName()); 
    private final Properties jndi = new Properties(); 

    public MyProps() { 
     try { 
      loadJNDI(); 
      String name = jndi.getProperty("name"); 
     } catch (IOException ex) { 
      Logger.getLogger(MyProps.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 

    public Properties getJNDI() { 
     return jndi; 
    } 

    private void loadJNDI() throws IOException { 
     jndi.load(MyProps.class.getResourceAsStream("/jndi.properties")); 
    } 

} 

更重要的是,應該主要被命名爲值是多少?

---------------------------------------------- --------編輯-------------------------

java.naming.factory.initial = TO_BE_CHANGED_BY_USER java。 naming.factory.object = TO_BE_CHANGED_BY_USER java.naming.factory.state = TO_BE_CHANGED_BY_USER java.naming.factory.control = TO_BE_CHANGED_BY_USER java.naming.factory.url.pkgs = TO_BE_CHANGED_BY_USER java.naming.provider.url的= TO_BE_CHANGED_BY_USER java.naming.dns.url = TO_BE_CHANGED_BY_USER

from:

http://www.pressinganswer.com/433577/how-to-access-datasource-in-geronimo-via-jndi-by-remote-client-application

回答

1

你需要爲每個供應商的文檔中查找,你的情況,比如CosNaming提供商,在JNDI documentation page

+0

爲什麼它是COS而不是RMI? java的意圖是java,用於遠程調用EJB。感謝您的鏈接,我正在研究它。 – Thufir 2014-09-13 03:06:15

+1

因爲你使用'com.sun.corba.ee.impl'作爲開始。 EJB通常使用RMI/IIOP,而後者使用COSNaming。 – EJP 2014-09-13 03:13:40

相關問題