I have a file users.txt
with a file path of myPlugin/impl/src/main/resources/myPlugin/impl/src/main/java/com/company/myPlugin/impl/users.txt
. I am trying to access this file from a Java class with a file path of myPlugin/impl/src/main/java/com/company/myPlugin/impl/UserManager
. I don't want to hardcode a path because the working directory will change. I did try:
String path = System.getProperty("user.dir") + .....path to users.txt;
The problem with this is that it only works when I run the plugin locally. When it is deployed on another machine or server, the working directory won't contain all the files. What I really need is a way to open the file using only a relative path from myPlugin
. I also tried
URL path = getClass.getResource("");
And then added the rest of the path but this did not work either. Is it even possible to use only a relative path that is not dependent on the current working directory? When I run my plugin on the server, the working directory does not contain the source code or directory structure.