• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Absolute path issue while restarting Linux Server

 
Greenhorn
Posts: 27
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:
[/code]

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: 28319
210
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.
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic