I have a Java web application (Eclipse/OSGI) on a Jetty server. I want to be able to serve static files to my web application from a folder outside of the web root. In my web application, I don't yet know the file name of the file I want to be served, so I want to take the filename (and/or path) as a VM parameter when I start my web application. For example:
I have an image - myImg.jpg - that I have put in a folder on the server file system, for example root/images/myImg.jpg. I want to take this as a VM parameter, e.g. "-DmyImg=/images/myImg.jpg/" so that I can get the image and display it on my web page. How can I accomplish this? Can I do this without creating a new Servlet?
Thanks in advance for any help!
Solved it!
This is what I added to my jetty.xml file:
@Farna: In your answer I am not able to understand how you are passing the file name as VM parameter. This is what I did.
I created
testparvez.xml
file in jettywebapps
directory.Then I start jetty as
And finally I access from url
http://localhost:8082/testparvez/