Jump to content

[Solved] Where to put a text file for the WAR to read?


Recommended Posts

Posted

Hi

 

I need my WAR to read some settings from a file.

After deploying it, where should I put the file (text file) so my WAR can read it?

How can I know the absolute/relative path to the file from the WAR?

Do I need a special permissions just to read this file?

 

Thanks

 

 

Posted

You can put it in your home folder or anywhere inside it and use the absolute path to the file inside your home folder (which will probably be something like /home/username/filename.txt or /home1/username/filename.txt, I can't find your account so I can't get you the exact path).

 

Just make sure to give the file "other read" permissions (644 is probably fine, it's the last 4 that matters) so the Tomcat process can access it. Tomcat runs as another user, not as you, so "other" has to be given read access if you want it to not return an access denied error.

Posted

Thank you very much, so my path should be /home/stockdi1/filename.txt and 644 as the permissions.

I now see that it's the same folder as the war itself, so I guess I can simply write

InputStream inputStream = new FileInputStream("filename.txt");

and if it won't work, use the absolute path

InputStream inputStream = new FileInputStream("/home/stockdi1/filename.txt")

Thanks

 

btw: Until 2 days ago, I saw a deadline to my Java access, 2 days ago it changed back to "Your account is in the queue to receive java support. It should be installed soon." and it's like that since... I hope the counting didn't start from the beginning :-)

Posted

If you use the path "filename.txt" then that might mean you won't be able to change the contents of the file without either using the deployed app to change it or redeploying your .war completely because the absolute path will be "/opt/tomcat/live/webapps/stockdi1_warname/filename.txt". If you want to be able to edit the file while the .war is running or read the file then Wolstech's suggestion of "/home/stockdi1/filename.txt" might be more appropriate.

 

If the install date says a date like 2019-03-10 then that means your number 2+ in line to receive java. If it says java should be installed soon that means you're next in line.

Posted (edited)

Yeah, only after posting my previous message I realized that the WAR is there because from there it is being deployed and it's not where it actually runs. I will use

InputStream inputStream = new FileInputStream("/home/stockdi1/filename.txt")

It said 2019-03-09 or 2019-03-10 until 2 days ago and since then it's just "java should be installed soon", I guess I'm next then.

 

edit: I got it, thanks!

 

Thanks!

Edited by Amoss

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...