This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line!
See this thread for details.
Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Absolute path issue while restarting Linux Server

Posts: 26
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I have recently started working as a junior java developer and my first task was to create two reports from the database and send it to the management everyday. The application is in a Linux Server and my report generation was working fine until one day the Linux server was restarted and following was the error in the log file:

However, restarting tomcat seems to solve the problem and the report started running fine again. I spoke to our Linux admin and he was not able to help . I tried to replicate this issue in our development environment and added the path of the reports to the log file to find exactly what is happening and following is what I have found:

This is the code for creating the report :

The name of the application is BusinessReportScheduler and the tomcat is installed under BusinessReportScheduler/bin. We deploy our application through AzureDevOps and tomcat shutdown and restart is handled by the pipeline. Looking into the log file for the path where the report is created I found that whenever the tomcat is restarted , the report creation is working fine and is created in the following path :/BusinessReportScheduler/bin/Complaints.xls and /BusinessReportScheduler/bin/Events.xls

However when the Linux server is restarted , its trying to create the report in the root of the linux server :/Complaints.xls and /Events.xls and that is when it is failing throwing exception as we do not have write permissions in the linux server root:

My solution is to create a folder under BusinessReportScheduler and then explicitly use the path of that folder to write the reports into. But can anyone please let me know why the code tries to create the reports in the root of the linux server when the server is restarted and why does it create the report under the bin folder when tomcat is restarted?

I am relatively new to programming so please don't mind is this is too naive.

Saloon Keeper
Posts: 23441
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should never use relative filename paths in a webapp. The current directory (used as the reference point for the file) may get changed without notice. There is only one "current directory/working directory" per JVM, and Tomcat has lots of threads that could potentially change it.

So always use absolute paths. You may find it useful to define the directory path for your file as a webapp environment variable so that the app can read it using JNDI. That allows you to select an alternative location without rebuilding the webapp. It's especially useful when switching back and forth between Unix-like OS's and Windows, since the conventions for where to store data files is so different between them.
I found some pretty shells, some sea glass and this lovely tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
    Bookmark Topic Watch Topic
  • New Topic