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

Need help regarding Server's Real Path.

 
Bitan Biswas
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my Java Web Application, I need to dynamically create directories and upload files. For that I need the Real Path of the container. I use the following code



these two are working fine when i ran the application in localhost. it returns /home/xen/NetBeansProject/WebApp

but when I upload the project as a war file in my Internet server, it is not working. every times it return null.

Can you give me any suggestion regarding this?? Thank You.
 
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
You can't get the file path into a war file. It's war file... there's no file system!

Besides, you shouldn't be adding files into the web app itself -- how on Earth do you expect to be able to redeploy the app with changes?
 
Stefan Evans
Bartender
Pie
Posts: 1670
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than using getRealPath, I would suggest that you find out a directory on the server that your provider lets you write to, and include it as a property in your web app.

ie rather than using the ServletContext getRealPath method, retrieve it from a parameter you have set.

Agreed, it makes the installation of your site more complicated, as you now need to configure an additional piece of information somewhere, but it does have the advantage that you can specify anywhere - not just within the application path.
Possible places to put the property:
- in a properties file under the WEB-INF directory
- in the web.xml as a context property
- in a database
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic