I try to read a .txt file line by line in my code, which I placed it just right under the /src/ directory, when I run it with test case or with static void main
The short answer is that you can't change a running application's current working directory in Java; see Changing the current working directory in Java?
Setting the user.dir property won't work, because that doesn't affect the actual current directory that the OS uses when resolving pathnames for the application.
Setting the -Duser.dir on the command line won't work either. Rather, you have to:
cd to the relevant directory before running the application, ProcessBuilder, set the working directory using the directory(File) method, orFinally, what you are trying to do is (IMO) a bad idea:
$CATALINA_HOME/bin. (This is wrong ... but your hack will break it.)A better approach is to do something along the lines of @Eng.Fouad's answer.