6

VFS 方法无法处理JBoss解析到的${jboss.server.temp.dir}/local/outgoing配置的这个 URI。当我尝试解析 URI 并获取文件时,它会引发异常。任何想法可能是什么问题?jboss-beans.xml"C:\\Download\\jboss-eap-5.1.1\\server\\default\\tmp/local/outgoing"

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);
4

5 回答 5

11

很老的问题,但很受欢迎。这个例外很笼统。就我而言,将文件上传到远程 ftp 服务器时引发了此异常。根本原因是类路径中缺少 sftp 库。就在此异常之前,vfs尝试使用与中提到的方案相对应的提供程序之一来解析文件URI

就我而言,方案是sftp并且它试图jsch在类路径上找到库。由于它不存在于我的类路径中,因此引发了此异常。因此,必须将提供程序 jar 保留在类路径中。

于 2020-06-13T11:23:43.183 回答
7

对于面临这个问题的其他人:我通过替换摆脱了这个错误

FileSystemManager fsManager = VFS.getManager();

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

这使我可以多次使用文件系统管理器,而不会再出现问题中描述的错误。完成后不要忘记关闭您fsManager

fsManager.close();
于 2013-08-09T18:08:34.793 回答
6

@Manish Bansal - 感谢您对此问题的回复。我尝试了所有方法,但仍然遇到相同的错误:线程“main”org.apache.commons.vfs2.filesystemexception 中的异常:找不到带有uri“sftp://.....”的文件,因为它是相对路径,并且没有提供基本 uri。

在我的 MAVEN 项目中,我必须添加对 'jsch' 的依赖项并且它起作用了。

因此,简而言之,我添加了以下 POM 依赖项:

<!-- 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;
    }
于 2020-08-12T20:23:42.193 回答
1

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

于 2011-11-05T01:33:09.453 回答
0

只是为了补充已经提供的正确答案。
简而言之:检查VFS 依赖关系表以了解您使用的 VFS 功能。


当我第一次尝试连接时遇到了类似的问题FTP不是原始问题中的 SFTP)。我将 Maven 与 IntelliJ IDEA 一起使用。
我查看了VFS 官方文档,发现以下内容:

  1. 一些VFS 项目依赖项是可选的,默认情况下不安装
  2. 需要安装的内容在 VFS 下载和构建页面的表格中。
    确实,JSch对于是必需的SFTP,对于Apache Commons Net是必需的FTP,等等。

Commons Net我通过 Maven安装后,我的 FTP 连接就开始工作了。

于 2022-01-02T22:58:31.833 回答