Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Absolute path issue while restarting Linux Server

 
Greenhorn
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:
[/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: 23252
158
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.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic