我有一个任务要完成。我想连接到 SVN 存储库,并且必须使用 java 代码将所有目录和文件从 svn 下载到我的本地系统。我对此很陌生,并尝试使用示例来读取单个文件内容http://svnkit.com/kb/dev-guide-commit-operation.html但在获取文件内容和属性时出现类似错误的异常: svn: E170001: ' 需要身份验证https://netspurt.unfuddle.com:443解开颠覆存储库'。请任何人可以详细解释一下
以下代码对我有用:
private static SVNClientManager ourClientManager;
public void DownloadWorkingCopy(String svnLocation,String svnUserName,String svnPassword){
String locationForSVNProj="C:\\SVNLOC";
DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
ourClientManager = SVNClientManager.newInstance(options, svnUserName, svnPassword);
SVNUpdateClient updateClient = ourClientManager.getUpdateClient( );
updateClient.setIgnoreExternals( false );
SVNRevision rev=SVNRevision.HEAD;
File file=new File(locationForSVNProj);
try{
long revision1=updateClient.doCheckout( SVNURL.parseURIEncoded(svnLocation) ,file , rev , rev , true);
}catch(Exception e){e.printStackTrace();}
}
“需要身份验证”问题意味着服务器需要身份验证,但您没有提供正确的信息ISVNAuthenticationManager
实施到SVNClientManager
。 SVNKit 支持不同的身份验证方式。
如果您知道您的凭据是什么并且它们是固定的,您可以使用BasicAuthenticationManager
执行。
如果您想使用存储在您的~/.subversion
目录、使用DefaultSVNAuthenticationManager
实现(有一个方便的方法来构造它:SVNWCUtil.createDefaultAuthenticationManager()
但请注意,这对应于 Subversion 命令--non-interactive
选项)。如果您需要允许从控制台输入密码的身份验证管理器,请查看 SVNCommandEnvironment#createClientAuthenticationManager() 实现。
最后我想注意到 SVNClientManager 已经过时了(尽管仍然受支持)。相反,我更喜欢 SvnOperationFactory 类,就像我的另一个那样answer,它还有 setAuthenticationManager() 设置器。
如果这很重要的话,我是 SVNKit 开发人员之一。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)