Hi Fabio,
ClassLoader.getResource() can only be used to access resources on your
classpath.
"docroot" is normally NOT on your classpath. Your classpath will be something
like:
WEB-INF/classes
WEB-INF/lib/*.jar
CATALINA_BASE/lib/*.jar
JRE_HOME/lib/*.jar
To get the path of a File in your Webapplication, try something like:
String path = context.getRealPath("/docroot/img/MyFile");
where context is your ServletContext.
The ServletContext can be obtained by:
context = request.getServletContext();
from a request, or by:
config.getServletContext()
from inside the init() method of any Servlet.
Regards from Vienna,
Richard
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]]
Im Auftrag von Fabio Paroni (via Magnolia Forums)
Gesendet: Donnerstag, 24. Mai 2012 11:46
An: Magnolia User List
Betreff: [magnolia-user] Get files path
Hi guys,
I placed a file in the Magnolia Java webapp project like this:
>src
>main
>webapp
>docroot
>img
>[u]MyFile[/u]
Now in a java class I need the path of MyFile.
I'm trying to use ClassLoader.getResource("img/MyFile") function but I always
get null.
Any ideas?
Thanks in advance
Fabio
--
Context is everything:
http://forum.magnolia-cms.com/forum/thread.html?threadId=8edfc2c4-d03b-4efd-ba9d-2d9c21d8757f
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------