Search code examples
javafileweb-applicationsweblogic

Where will WebLogic look for files by default?


I have a web application deployed in WebLogic. In one of my java file, I tried to read PleaseNote.txt as following:

File file = new File("PleaseNote.txt");

Now WebLogic is taking PleaseNote.txt from its domain directory.My question is:

  1. Why it is domain directory? Why not the directory where my java file which has the above line of code is in?

  2. Is there any configuration which I am not aware of , but did unknowingly, for WebLogic to look in its domain directory?

  3. What are the implications / side effects of using above line of code in production?

Any WeLogic experts, please respond.

Thank you Regards Chaitanya


Solution

  • Reading a file using that way makes your application less portable and not very robust: if you deploy your application on another application server, you'll have to find out where to put that PleaseNote.txt file again or the code will break.

    This breaks the WORA (Write Once, Run Anywhere) principle and I'd consider this as a bad practice.

    So, I'd rather put this file in the classpath and use ClassLoader#getResourceAsStream(String name) to read it.