Chaitanya MSV
Chaitanya MSV

Reputation: 6784

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

Upvotes: 0

Views: 5413

Answers (3)

Pascal Thivent
Pascal Thivent

Reputation: 570595

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.

Upvotes: 3

Salandur
Salandur

Reputation: 6453

when using new File(..) java looks for the file in the directory from where java.exe is started. In case of an weblogic domain, this is ofcourse the domain directory. This is default java behaviour.

When you want to load a file that is in de same directory as the class-file you are loading from, use ClassLoad.getResourcesAsStream(). If you want to load a resource from the classpath use the same method, but prefix your file with "/".

Upvotes: 0

Alexander Rozhkov
Alexander Rozhkov

Reputation: 81

It is domain directory because it's corresponds to value of user.dir system variable, the place where java reads/writes files if path not explicitly set.

Why domain directory corresponds to user.dir ? Because you start Weblogic server here.

Regards Alexander Rozhkov

Upvotes: 0

Related Questions