Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从我的Java Web服务访问.properties文件_Java_Web Services_Tomcat_Axis2 - Fatal编程技术网

如何从我的Java Web服务访问.properties文件

如何从我的Java Web服务访问.properties文件,java,web-services,tomcat,axis2,Java,Web Services,Tomcat,Axis2,我已经使用tomcat成功地部署了java web服务。此web服务正在访问配置文件(.Properties)。我已将config.Properties文件放在以下目录中 C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ProcurementWS1\WEB-INF\classes\MainPackagePr ProcurmentWS1是WAR文件的名称 这是我试图从我的代码访问它的方式: Properties pro

我已经使用tomcat成功地部署了java web服务。此web服务正在访问配置文件(.Properties)。我已将config.Properties文件放在以下目录中

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ProcurementWS1\WEB-INF\classes\MainPackagePr
ProcurmentWS1是WAR文件的名称

这是我试图从我的代码访问它的方式:

Properties properties = new Properties();
            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("procwsconfig.properties");
            properties.load(is);
我在加载时收到一个空指针异常


你能告诉我我做错了什么吗?

把它放在src/config中,直接放到源代码中的config包中,编译后它会转到/WEB-INF/classes/config/config.properties

this.getClass().getResourceAsStream(“/config/config.properties”)

然后我在同一个项目中创建了一个服务类,它有一个方法

public static InputStream getConfigAsInputStream(){
    return Service.class.getResourceAsStream("/config/config.properties");
}

将它放在源代码中的src/config direct to config包中,构建后它将转到/WEB-INF/classes/config/config.properties

this.getClass().getResourceAsStream(“/config/config.properties”)

然后我在同一个项目中创建了一个服务类,它有一个方法

public static InputStream getConfigAsInputStream(){
    return Service.class.getResourceAsStream("/config/config.properties");
}

您可以使用以下方法将其放置在类路径的某个位置以及.java源文件的任何文件夹下:

 ResourceBundle bundle1 =         ResourceBundle.getBundle("com.witness.web.license.l10n.VersionsFileName");
    String fileName = bundle1.getString("11.1");  

com.witness.web.license.l10n
作为您的包

您可以使用以下方法将其放置在类路径的某个位置以及.java源文件的任何文件夹下:

 ResourceBundle bundle1 =         ResourceBundle.getBundle("com.witness.web.license.l10n.VersionsFileName");
    String fileName = bundle1.getString("11.1");  

com.witness.web.license.l10n
作为您的包

1)将您的属性文件放在项目中(WAR文件中)。2) 把它放在classpathWell上的某个地方。我正在使用eclipse,我将该文件包含在java构建路径中,但它不起作用1)将属性文件放在项目中(WAR文件中)。2) 把它放在classpathWell上的某个地方。我正在使用eclipse,我将该文件包含在java构建路径中,但没有成功