Java 如何获取jndi.properties文件

Java 如何获取jndi.properties文件,java,jboss,jndi,Java,Jboss,Jndi,我想使用我的jndi.properties文件,但它给我错误消息。我正在尝试使用以下代码获取文件: public class EJBTester { ... Properties props; InitialContext ctx; { props = new Properties(); InputStream inputStream = this.getClass().getClassLoader()

我想使用我的jndi.properties文件,但它给我错误消息。我正在尝试使用以下代码获取文件:

public class EJBTester {

...

    Properties props;
    InitialContext ctx;
    {
        props = new Properties();
        InputStream inputStream = this.getClass().getClassLoader()
                .getResourceAsStream("/jndi.properties");
        try {
            props.load(inputStream);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        try {
            ctx = new InitialContext(props);
        } catch (NamingException ex) {
            ex.printStackTrace();
        }
    }
...
}
我的jndi.properties文件位于我的项目的主包中,如下所示:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost
我正在使用jboss 6.2 eap。错误如下:

Exception in thread "main" java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Properties.java:434)
    at java.util.Properties.load0(Properties.java:353)
    at java.util.Properties.load(Properties.java:341)
    at com.tutorialspoint.test.EJBTester.<init>(EJBTester.java:26)
    at com.tutorialspoint.test.EJBTester.main(EJBTester.java:40)
换句话说,这一行ctx=新的InitialContextprops;无法加载道具


如何加载这个jndi.properties文件?

与其说是jndi问题,不如说是资源加载问题。jndi.properties文件在哪里?EJBTester类在哪里?EJBTester在com.tutorialspoint.test;包中;。默认包中有jndi.properties,但我认为找到了jndi文件,因为如果我更改名称,它会给我另一个错误,即找不到jndi.properties!为什么?它会自动加载。您不必自己加载它。那么如何获取InitialContext?呃,新的InitialContext?