I have a small runnable JAR application that creates a file.
It works from eclipse, and does not work from JAR.
OutputStream os=new FileOutputStream("C:\\temp\\props.xml");
TransformerFactory tf=TransformerFactory.newInstance();
Transformer trans=tf.newTransformer();
trans.transform(new DOMSource(doc), new StreamResult(os));
There are no errors, nothing breaks, user message is shown like file is created, but there is no file.
Similar topic exists: link, but there is no solution for my problem.
It's probably some file/folder win permission issue.
Is there a way I could allow writing to a file from JAR?
I tried making a java.policy file:
grant
{
permission java.io.FilePermission "C:\\xxx", "write";
};
I placed that policy file in the same folder where my JAR is, but it didn't helped.
Edit: Reading was the problem. I placed some file in my project and tried to read it like:
File file=new File("someFile.txt");
FileInputStream file_inputstream=new FileInputStream(file);
It was ok for eclipse, but not ok for JAR. When I placed this file outside JAR and read it with apsolute file path it worked.