SVN服務器可通過https訪問。所以我需要讀取一個位於那裏的文件。我跟着從svnkit維基(http://svn.svnkit.com/repos/svnkit/tags/1.3.5/doc/examples/src/org/tmatesoft/svn/examples/repository/DisplayFile.java)的片段,但我的SVNKindNode
是NONE
,因此沒有文件被讀取。儘管如此,連接過程中也沒有例外。所以我可以假設我確實正確連接到SVN服務器,但出現問題。使用svnkit通過https從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。
你可以檢查一個公共文件/服務器,所以它可以重現其他人嗎? – mstrap
是的,我甚至試圖從svnkit(鏈接在消息中)和結果是相同的(他們在例子中使用自己的公共svn)。 – Dragon
http://svn.svnkit.com/repos/svnkit/trunk/www/license.html給出了404.我很確定你的情況,URL或文件路徑是錯誤的。您在訪問瀏覽器中的完整網址時是否可以看到該文件? – mstrap