FS#21475 - [tomcat] changing -Djava.io.tmpdir in /etc/rc.d/tomcat doesn't take effect
Attached to Project:
Arch Linux
Opened by Francesco Antonacci (punkeroso) - Tuesday, 26 October 2010, 09:14 GMT
Last edited by Guillaume ALAUX (galaux) - Monday, 08 November 2010, 20:32 GMT
Opened by Francesco Antonacci (punkeroso) - Tuesday, 26 October 2010, 09:14 GMT
Last edited by Guillaume ALAUX (galaux) - Monday, 08 November 2010, 20:32 GMT
|
Details
Description:
-I need to read a file from my webapps. The problem is that tomcat seems to ignore where his home is set in /etc/rc.d/tomcat. Using this piece of code: String s = new File(".").getAbsolutePath(); FileWriter fstream = new FileWriter("/opt/tomcat/webapps/out.txt"); BufferedWriter out = new BufferedWriter(fstream); out.write(s); out.close(); It gives me "/", in fact, if I put my file in the root of the disk and try to open it giving only the filename, It opens it! Tomcat should not look in his catalina.home, catalina.base, or, at least, in java.io.tmpdir? Additional info: * package version(s) tomcat 5.5.31-2 * config and/or log files etc. -user tomcat \ -home $TOMCAT_JAVA_HOME \ -Dcatalina.home=/opt/tomcat \ -Dcatalina.base=/opt/tomcat \ -Djava.io.tmpdir=/opt/tomcat/temp \ Steps to reproduce: Same as above. |
This task depends upon
Closed by Guillaume ALAUX (galaux)
Monday, 08 November 2010, 20:32 GMT
Reason for closing: Not a bug
Additional comments about closing: Is a programming issue
Monday, 08 November 2010, 20:32 GMT
Reason for closing: Not a bug
Additional comments about closing: Is a programming issue
File baseDir = new File(getServletContext().getRealPath(""));
File outDir = new File(baseDir, "out");
if (!outDir.mkdirs()) {
logger.log(Level.SEVERE, "Could not mkdirs: \""+outDir.getAbsolutePath()+
"\" \nNo reports can be created.");
return;
}
this create directory "out" at $CATALINA_HOME/webapps/MyApp/
And this:
fopFactory.setUserConfig(getServletContext().getRealPath("/fop/conf.xml"));
loads file $CATALINA_HOME/webapps/MyApp/fop/conf.xml
> ...
> FileWriter fstream = new FileWriter("/opt/tomcat/webapps/out.txt");
You won't read a file from your webapp with its absolute path. If this out.txt is in you WAR or EAR then you will need to use its relative path within the WAR/EAR.
BTW, are you trying to read or write ("FileWriter", "out.txt", ...)?
Anyway, this really looks like a Java programming issue rather than a Tomcat/Arch packaging one.
What I want to know is what "new File(".").getAbsolutePath();" should give me. It shouldn't give me the Tomcat's home, ie -Dcatalina.home or base (/opt/tomcat)?
If not, what are that variables for?
> What I want to know is what "new File(".").getAbsolutePath();" should give me. It shouldn't give me the Tomcat's home, ie -Dcatalina.home or base (/opt/tomcat)?
> If not, what are that variables for?
That should give you the absolute path of the current directory (".").
<out of topic>
"Current dir" doesn't really mean anything for a webapp. So if you are trying to read a file that belongs to your webapp you shouldn't use an absolute path (which would make you hard code the path) rather than a relative path within your webapp ie something like "resource/myfile".
But this is not the place to talk about Java issues ;)
</out of topic>