Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get absolute path of linked resource outside of Tomcat

 
John Dunning
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get the absolute path from a relative path. The problem is that the file I'm trying to access is not under the /Tomcat/ directory. Currently I can link to the file using a relative path, but I need to use the File object to iterate through the files in the directory.

For clarification, I'm running cruisecontrol on Tomcat 5.5. The JSP files are in D:\Tomcat\webapps\cruisecontrol. However, the log files are in C:\logs. Because of the way cruisecontrol is configured I can link to the "C:\logs\project\cruisecontrol.log" using the relative path 'href="<%= artifacts_url %>/cruisecontrol.log', where artifacts_url="/logs/project/". I've tried to read that as a File object to then getAbsolutePath(), but haven't had any luck yet.

Is what I'm trying to do possible? Please let me know if I can be more clear in the asking of this question.

TIA, John
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're probably looking for getRealPath
[ July 31, 2007: Message edited by: Ben Souther ]
 
John Dunning
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply; unfortunately, that still gives me the path to the Tomcat installation directory plus the filename, even though that file is not there.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As your file is outside the purview of the web app, there is no way to automatically determine its path. You'll need to provide it. Rather than hard-coding it, consider using a context parameter or even a properties file.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18020
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To amplify on Bear's statement: A URL is not the same thing as a file path. They may look like file paths. They are often mapped to file paths. But they're not the same thing as file paths. A web server is not the same thing as a file server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic