JavaMelody存储路径始终指向Tomcat临时目录问题求助
Let me walk you through solving this frustrating path configuration problem with JavaMelody 1.82.0 on Windows Tomcat 8.5.34.
Root Cause
The key mistake here is misunderstanding how JavaMelody interprets absolute paths on Windows. As per the docs, Windows requires an absolute path to start with a drive letter + backslash (like C:\folder) or a leading backslash for network shares (e.g., \\server\share). Your attempts using /srv/data/... (Unix-style absolute path) or \srv\data\... (no drive letter) are being treated as relative paths to Tomcat's temp directory—hence the weird temp\srv\data\foo\javamelody path you're seeing.
Step-by-Step Fixes
Use Windows-native Absolute Path Format
Update yourcontext.xmlto use a valid Windows absolute path with a drive letter. You can use either escaped backslashes or forward slashes (XML-friendly, no escaping needed):<Context path="/foo" docBase="foo.war" reloadable="false"> <!-- Option 1: Escaped backslashes for XML compatibility --> <Parameter name='javamelody.storage-directory' value='D:\\srv\\data\\foo\\javamelody' override='false'/> <!-- Option 2: Forward slashes (works natively on Windows too) --> <!-- <Parameter name='javamelody.storage-directory' value='D:/srv/data/foo/javamelody' override='false'/> --> <Parameter name='javamelody.log' value='true' override='false'/> </Context>Either format will be recognized as an absolute path by JavaMelody.
Verify Directory Permissions
Make sure the user running Tomcat has read/write permissions on the target directoryD:\srv\data\foo\javamelody. If Tomcat can't access the directory, JavaMelody will silently fall back to using thetempdirectory as a fallback.Check for Conflicting Configurations
Double-check yourWEB-INF/web.xmlto ensure there's no duplicatejavamelody.storage-directoryparameter defined there. If web.xml has the parameter, yourcontext.xmlsetting will be ignored (since you setoverride='false'—it prevents web.xml from overriding context.xml, but if web.xml defines it first, context.xml won't overwrite it). Either remove the web.xml entry or setoverride='true'in context.xml to prioritize that value.
How to Confirm It's Working
After restarting Tomcat:
- Visit your JavaMelody monitoring endpoint (e.g.,
http://your-server:port/foo/monitoring) - Scroll to the bottom of the page, look for "Storage directory" in the System Information section
- It should now show your target absolute path instead of the temp directory path.
内容的提问来源于stack exchange,提问作者Pwnstar

