Question

The VFS method cannot process this URI ${jboss.server.temp.dir}/local/outgoing configured in jboss-beans.xml which is resolved to "C:\\Download\\jboss-eap-5.1.1\\server\\default\\tmp/local/outgoing" by JBoss. When I try to resolve the URI and get the file, it throws an exception. Any ideas what could be the problem?

Exception

17:35:25,024 ERROR [VfsSynchronizerConfImpl] File FromOutgoing cannot be resolved, FileSystemException:
org.apache.commons.vfs2.FileSystemException: Could not find file with URI "C:\Download\jboss-eap-5.1.1\server\default\tmp/local/outgoing" because it is a relative path, and no base URI was provided.
    at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:719)
    at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:649)
    at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:605)

DefaultFileSystemManager.class methods

public FileObject resolveFile(final String uri) throws FileSystemException
  -- this method calls the method below

public FileObject resolveFile(final FileObject baseFile, final String uri,
        final FileSystemOptions fileSystemOptions)
        throws FileSystemException
  -- this method cannot process the string and throws
     throw new FileSystemException("vfs.impl/find-rel-file.error", uri);
Was it helpful?

Solution

I think it needs the file: scheme because the error says it's asumed to be relative.

OTHER TIPS

For other people facing with this issue: I got rid of this error by replacing

FileSystemManager fsManager = VFS.getManager();

with

StandardFileSystemManager fsManager = new StandardFileSystemManager();
fsManager.init();

This allowed me to use the file system manager multiple times without getting the error anymore described in the question. Don't forget to close you fsManager when you're done with it:

fsManager.close();

Quite old question but popular. This exception is quite generic. For my case, this exception was thrown while uploading files to remote ftp server. And the root cause was missing sftp library in classpath. Just before this exception, vfs tries to resolve the file using one of the provider corresponding to the scheme mentioned in URI.

For my case, scheme was sftp and and it tried to find jsch library on classpath. Since, it was not present on my classpath, this exception was thrown.Therefore, one must keep the provider jar on classpath.

@Manish Bansal - thank you for your reply on this issue. I tried everything but was still getting the same error: exception in thread "main" org.apache.commons.vfs2.filesystemexception: could not find file with uri "sftp://....." because it is a relative path, and no base uri was provided.

In my MAVEN project i had to add the dependency for 'jsch' & it worked.

So, in a nutshell i added the following POM dependencies:

<!-- SFTP -->
<dependency>
    <groupId>com.jcraft</groupId>
    <artifactId>jsch</artifactId>   version>0.1.55</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-vfs2</artifactId>
    <version>2.6.0</version>
</dependency>
    public void downloadFile() throws IOException {     
        FileSystemManager manager = VFS.getManager();
                
        FileObject remote = manager.resolveFile(createConnectionString("XYZ.com","ABC","LMNOP","/<FOLDER_NAME>/<FILE_NAME>"));
        FileObject local = manager.resolveFile(System.getProperty("user.dir") + "/" + "src//main//resources//");
        
        local.copyFrom(remote, Selectors.SELECT_SELF);
     
        local.close();
        remote.close();
    }
    
    public static URI createConnectionString(String hostName, String username, String password, String remoteFilePath) {        
        URI sftpURI = null;
        try {
            String userInfo = username + ":" + password;
            
            sftpURI = new URI("sftp",userInfo,hostName,-1,remoteFilePath,null,null);
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        return sftpURI;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top