My web service needs to read a properties file but cannot find it. The
properties file is currently in the jar containing the web service, so
the jar contains things like:
com.ncc.wrap.Configuration.class
....
com.ncc.wrap.StockService.class
...
data/config/stock.properties
The Configuration class reads the properties and the StockService class
uses them. When I run it as a normal jar, Configuration can find the
properties file (the jar is in the classpath), but running under Axis, I
get an exception that it cannot find the properties file. How do I tell
Configuration to find the file? The error I get in Tomcat's log is:
com.ncc.wrap.WRAPException: Unable to open file:
data/config/stock.properties
at com.ncc.wrap.Configuration.initialize(Configuration.java:160)
I have tried to use a servlet to help. The ConfigurationSerlet.java
class has a function:
public void init()
{
ServletContext sc = getServletConfig().getServletContext();
try
{
Configuration.initialize(sc);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
and I add to the Axis web.xml the following:
<servlet>
<servlet-name>WRAPConfiguration</servlet-name>
<servlet-class>com.ncc.wrap.ConfigurationServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
and change Configuration.java to include a function that takes a servlet
context in the initialization:
String resource = "/" + DEFAULT_CONFIG_FILE;
InputStream is = sc.getResourceAsStream( resource );
logger.info(" input stream was: " + is + ". Resource was: "
+ resource);
logger.info("servlet context" + sc );
wrapProperties.load(is);
However, the problem with this is that the InputStream 'is' is null.
I've tried lots of variations but no luck.
Any help would be greatly appreciated.
Clark