Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用svnkit通过https从SVN读取文件_Java_Svnkit - Fatal编程技术网

Java 使用svnkit通过https从SVN读取文件

Java 使用svnkit通过https从SVN读取文件,java,svnkit,Java,Svnkit,SVN服务器可通过https访问。所以我需要读取一个位于那里的文件。我遵循了svnkit wiki()中的代码片段,但是我的SVNKindNode是NONE,因此没有读取任何文件。然而,在连接过程中没有例外。所以我可以假设我确实正确地连接到了SVN服务器,但随后出现了一些问题 代码如下: public class SVNRepoConnector { private String username = "user"; private String password = "pwd"

SVN服务器可通过https访问。所以我需要读取一个位于那里的文件。我遵循了svnkit wiki()中的代码片段,但是我的
SVNKindNode
NONE
,因此没有读取任何文件。然而,在连接过程中没有例外。所以我可以假设我确实正确地连接到了SVN服务器,但随后出现了一些问题

代码如下:

public class SVNRepoConnector {
    private String username = "user";
    private String password = "pwd";
    private String baseUrl = "https://mysvnserver.com/svn/project/trunk";
    private String filePath = "/myproject/src/main/webapp/file.html";

    public void downloadSchema() {
        DAVRepositoryFactory.setup();
        SVNRepository repository = null;

        try {
            repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(baseUrl));
            ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password);
            repository.setAuthenticationManager(authManager);

            SVNNodeKind nodeKind = repository.checkPath(filePath, -1);

            if(nodeKind == SVNNodeKind.NONE) {
                System.err.println("There is file at: " + baseUrl + filePath);
                System.exit(1);
            } else if (nodeKind == SVNNodeKind.DIR) {
                System.err.println("The entry at " + baseUrl + filePath + " is a directory while a file was expected.");
                System.exit(1);
            }

            SVNProperties properties = new SVNProperties();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            repository.getFile(filePath, -1, properties, out);

            System.out.println("Content:\n");
            try {
                out.writeTo(System.out);
            } catch (IOException e) {
                e.printStackTrace();
            }

        } catch (SVNException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SVNRepoConnector connector = new SVNRepoConnector();
        connector.downloadSchema();
    }
}
由于SVNNodeKind等于无,我收到“有文件在…”。我不明白这里出了什么问题。如何通过https从SVN读取文件

顺便说一句,我的svnkit是1.8.5。

指定一个相对路径(除非
baseUrl
是存储库根目录):

而不是

private String filePath = "/myproject/src/main/webapp/file.html";

我在彻底调试源代码后找到了解决方案

简而言之,问题在
repository.checkPath(filePath,-1)的第二个参数中
repository.getFile(filePath,-1,properties,out)
filePath
必须是文件名,并且它的路径必须在
baseUrl
字段中。在这些更改之后,一切都开始正常工作


关于代码片段,在
www/license.html
的情况下,应该将
1
作为第二个参数传递。

您可以使用公共文件/服务器进行检查,以便其他人可以复制它吗?是的,我甚至尝试了svnkit的示例(链接在消息中),结果是相同的(示例中他们使用自己的公共svn)。给出了一个404。我敢肯定,在您的情况下,URL或文件路径都是错误的。在浏览器中访问完整的URL时,您能看到该文件吗?在我的情况下,路径是正确的。@以上问题中的代码工作正常。。您知道将整个目录复制到本地主机的过程吗??
private String filePath = "/myproject/src/main/webapp/file.html";