Estou querendo abrir um arquivo .porperties dentro de um action, só que recebo este erro:
java.io.FileNotFoundException: ../config/config.properties
Qual é o path que roda uma classe dentro do tomcat6?
Estou querendo abrir um arquivo .porperties dentro de um action, só que recebo este erro:
java.io.FileNotFoundException: ../config/config.properties
Qual é o path que roda uma classe dentro do tomcat6?
Como tu está carregando? Mostra o código
Esse .properties está no FileSystem? Ou dentro de um jar?
Ele fica em uma pasta dentro da minha aplicação.
App
- WEB-INF
- classes
- config
-config.properties
O código da action é esta:
package control;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.util.Properties;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ActionSupport;
public class ControlConfiguration extends ActionSupport implements Preparable{
private int thread;
private String host;
private String port;
private String databaseName;
private String username;
private String password;
private String pathRequest;
private String pathFileControl;
private String destinationPath;
private String destinationHost;
private Properties properties;
private String pathProperties = "../config/config.properties";
// Nome dos campos das propriedades
private static String THREAD = "THREAD";
private static String DATABASE_HOST = "DATABASE_HOST";
private static String DATABASE_PORT = "DATABASE_PORT";
private static String DATABASE_NAME = "DATABASE_NAME";
private static String DATABASE_USERNAME = "DATABASE_USERNAME";
private static String DATABASE_PASSWORD = "DATABASE_PASSWORD";
private static String PATH_SAVE_REQUEST = "PATH_TXT";
private static String FILE_CONTROL_IMPORTER = "FILE_CONTROL_IMPORTER";
private static String DESTINATION_PATH = "DESTINATION_PATH";
private static String DESTINATION_HOST = "DESTINATION_HOST";
private Properties getProperties(){
return this.properties;
}
//Metodo para carregar as propriedades na memória
private void setProperties(){
try{
FileInputStream input = new FileInputStream( this.pathProperties );
this.properties = new Properties();
this.properties.load(input);
input.close();
this.setThread(Integer.parseInt(this.getProperties().getProperty(ControlConfiguration.THREAD)));
this.setHost(this.getProperties().getProperty(ControlConfiguration.DATABASE_HOST));
this.setPort(this.getProperties().getProperty(ControlConfiguration.DATABASE_PORT));
this.setUsername(this.getProperties().getProperty(ControlConfiguration.DATABASE_USERNAME));
this.setPassword(this.getProperties().getProperty(ControlConfiguration.DATABASE_PASSWORD));
this.setPathRequest(this.getProperties().getProperty(ControlConfiguration.PATH_SAVE_REQUEST));
this.setPathFileControl(this.getProperties().getProperty(ControlConfiguration.FILE_CONTROL_IMPORTER));
this.setDestinationPath(this.getProperties().getProperty(ControlConfiguration.DESTINATION_PATH));
this.setDestinationHost(this.getProperties().getProperty(ControlConfiguration.DESTINATION_HOST));
} catch(FileNotFoundException e){
e.printStackTrace();
} catch(IOException e1){
e1.printStackTrace();
}
}
public void prepare(){
this.setProperties();
}
public String execute(){
this.getProperties().setProperty(ControlConfiguration.THREAD, String.valueOf(this.getThread()));
this.getProperties().setProperty(ControlConfiguration.DATABASE_HOST, this.getHost());
this.getProperties().setProperty(ControlConfiguration.DATABASE_PORT, this.getPort());
this.getProperties().setProperty(ControlConfiguration.DATABASE_NAME, this.getDatabaseName());
this.getProperties().setProperty(ControlConfiguration.DATABASE_USERNAME, this.getUsername());
this.getProperties().setProperty(ControlConfiguration.DATABASE_PASSWORD, this.getPassword());
this.getProperties().setProperty(ControlConfiguration.PATH_SAVE_REQUEST, this.getPathRequest());
this.getProperties().setProperty(ControlConfiguration.FILE_CONTROL_IMPORTER, this.getPathFileControl());
this.getProperties().setProperty(ControlConfiguration.DESTINATION_PATH, this.getDestinationPath());
this.getProperties().setProperty(ControlConfiguration.DESTINATION_HOST, this.getDestinationHost());
try{
FileOutputStream output = new FileOutputStream( this.pathProperties );
this.getProperties().store(output, "******* Properties ******");
output.close();
} catch(IOException e){
e.printStackTrace();
}
return SUCCESS;
}