Java 如何在启动时在IBM websphere application server内创建server.properties
我必须在服务器启动时在Websphere Application ND server的WEB-INF/classes中创建一个server.properties文件。下面的代码在我的本地Websphere windows上工作,但部署在群集上时,我看不到该文件。请帮助 代码段:Java 如何在启动时在IBM websphere application server内创建server.properties,java,Java,我必须在服务器启动时在Websphere Application ND server的WEB-INF/classes中创建一个server.properties文件。下面的代码在我的本地Websphere windows上工作,但部署在群集上时,我看不到该文件。请帮助 代码段: public class RuntimePropertyContextListener implements ServletContextListener { private Logger log = Logger.g
public class RuntimePropertyContextListener implements ServletContextListener {
private Logger log = Logger.getLogger(this.getClass());
public void contextInitialized(ServletContextEvent contextEvent) {
ServletContext context = contextEvent.getServletContext();
OutputStream output = null;
WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(context);
DynamicConfiguration dynamicConfiguration = (DynamicConfiguration) springContext.getBean("dynamicConfig");
try {
String sep = File.separator;
String contextPath = context.getRealPath("/WEB-INF/classes");
String propFilename = contextPath + sep + "server.properties";
String hostname = null;
File file = new File(propFilename);
if(!file.exists()){
InetAddress hostServerIp = InetAddress.getLocalHost();
if(hostServerIp != null){
hostname = hostServerIp.getHostName();
Properties prop = new Properties();
prop.setProperty("disable_lastrun", "true");
prop.setProperty("mrc_servlet_reload", "false");
prop.setProperty("mpower_server", dynamicConfiguration.getProperty("mpower_server"));
output = new FileOutputStream(file);
prop.store(output, null);
}
}
} catch (IOException io) {
io.printStackTrace();
}finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public void contextDestroyed(ServletContextEvent contextEvent) {
log.info("Context " + name + " Destroyed");
}
}