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.
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.
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.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
I found some pretty shells, some sea glass and this lovely tiny ad:
SKIP - a book about connecting industrious people with elderly land owners