If you are talking about an application properties file for application
properties you need to create a plugIn.
To do this you need to write a class and extend
org.apache.struts.action.PlugIn;
For example if you want to read an .properties file and load for global
access.
package com.plugin;
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.action.ActionServlet;
public class MyPlugIn implements PlugIn{
protected static final String PROPERTIES = "PROPERTIES";
public MyPlugIn(){
super();
}
public void init( ActionServlet servlet,
ModuleConfig moduleConfig ) throws
javax.servlet.ServletException{
Properties properties = new Properties();
String filePath = base + "WEB-INF" +
File.separator + "conf" +
File.separator + "myproperties.properties";
try{
File file = new File( filePath );
FileInputStream fis = new FileInputStream( file );
properties.load( fis );
//This is where you will retrieve the properties
//from when you need them (ActionServlet)
ServletContext context =
servlet.getServletContext();
context.setAttribute( PROPERTIES, properties );
log.msg( "Properties loaded!" );
}catch( Exception e ){
System.err.out( e.getMessage() )
}
}
public void destroy(){//Nothing to do}
}
Add the plugIn to the struts-config.xml
<plug-in className="com.MyPlugIn"/>
It will load when you start the web server.
-----Original Message-----
From: Simon Kelly [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 06, 2003 3:49 AM
To: Struts Users Mailing List
Subject: The loading of resource files at struts start-up.
Hi all,
Just a quick easy question. Will struts automatically load all files
suffixed with .properties from the resources directory into the local
context at start-up? Or do we have to wirte a declaration for each of the
files we want struts to acknowlege?
Cheers
Simon
Institut fuer
Prozessdatenverarbeitung
und Elektronik,
Forschungszentrum Karlsruhe GmbH,
Postfach 3640,
D-76021 Karlsruhe,
Germany.
Tel: (+49)/7247 82-4042
E-mail : [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]