write a file in jboss directory
I want to write in an xml file located under the conf directory of jboss.
I open it like this:
public void initialiserXml() {
sxb = new SAXBuilder();
try {
String fileXml= System.getProperty("jboss.server.home.dir").concat("/").concat("/conf").concat("/exempleMessage.xml");
System.out.println("Fichier xml " +fileXml);
document = sxb.build(fileXml);
racine = document.getRootElement();
System.out.println("Fichier Xml trouvé");
} catch (FileNotFoundException e) {
System.err.println("Aucun fichier XML trouvé");
} catc开发者_Python百科h (JDOMException e) {
System.err.println("Fichier XML mal construit");
} catch (IOException e) {
System.err.println("Impossible d ' ouvrir le fichier XML");
}
}
and after modification i write the change like this
public void enregistreFichier()
{
XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
try {
sortie.output(document, new FileOutputStream(fileXml));
} catch (FileNotFoundException e) {
System.err.println("Fichier XML source non trouvé");
} catch (IOException e) {
System.err.println("Impossible d ' ecrire dans le fichier XML");
}
}
This works on my test environment, but when I test this on a production environment (Linux server), it no longer works when i pass on sortie.output(document, new FileOutputStream(fileXml)); (FileNotFoundException)
I don t understand , my file is found when i open it with saxbuilder , but when i write in , i have a filenotfoundexception
How to solve the problem please?
thank you very much
FileNotFoundException is also thrown when you don't have all needed permission's to the file. In this case you might be missing write permission from /conf/exempleMessage.xml file
You should check which user is running jboss by giving command "ps -ef | grep jboss", it gives you a list all process witch name contains string jboss. After this you change ownership of file to that user by "chown : /conf/exempleMessage.xml"
精彩评论