Apache commons VFS cannot resolve files with String URI

  apache-commons-vfs, docker, java, spring, vfs

I’m trying to access and read files through a Spring boot web application by using Apache Commons VFS v2.6.0. The web application is running in a hosted docker container and a separate AWS storage was mounted in the same docker by targeting /mnt. When I try to access a file/folder inside the /mnt (ex: /mnt/abc/def/ghi.csv) using the below code,

fileSystemManager = VFS.getManager();
fileSystemManager.resolveFile("/mnt/abc/def/ghi.csv")

it throws the following exception.

Could not find file with URI "/mnt/abc/def/ghi.csv because it is a relative path, and no base URI was provided.

I have made sure that Jsch jar files are also available in the classpath(Jsch v0.1.54). the strange thing in here is I can read/write files using Java File IO without any problem in the same location.

Since it is saying the Base URI was not provided I’ve tried by giving the base file in Java File IO format and then it was able to resolve the file object.

fileSystemManager.resolveFile(new File("/mnt/abc/def"),"ghi.csv")

Once the base file is passed with the first call then it is working perfectly after that.

I’m using VFS to resolve files in both file: and sftp: schemes

Any idea to solve the issue in a better way? If we can set a base file when fileSystemManager is initializing for the first time and then resolving the files only by giving string path that would be ideal.

Source: Docker Questions

LEAVE A COMMENT