I have a task to complete. I Want to connect to SVN repository and have to download all directories and files from svn to my local system using java code. I am new to this and trying to use example to read single file content from http://svnkit.com/kb/dev-guide-commit-operation.html but it is giving exception like error while fetching the file contents and properties: svn: E170001: Authentication required for 'https://netspurt.unfuddle.com:443 Unfuddle Subversion Repository'. Please anybody can explain it detail
bellow code worked for me:
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();}
}
"Authentication required" problem means that the server requires authentication but you didn't provide correct
ISVNAuthenticationManager
implementation toSVNClientManager
. SVNKit supports different ways of authentication.If you know what your credentials are, and they are fixed, you can use
BasicAuthenticationManager
implementation.If you want to use credentials, stored in your
~/.subversion
directory, useDefaultSVNAuthenticationManager
implementation (there's a convenient method to construct it:SVNWCUtil.createDefaultAuthenticationManager()
but note that this corresponds to Subversion commands with--non-interactive
option). Look at SVNCommandEnvironment#createClientAuthenticationManager() implementation if you need authentication manager that would allow to enter password from console.And finally I'd like to notice that SVNClientManager is a part of obsolete (though still supported). Instead prefer SvnOperationFactory class like in my another answer, it also has setAuthenticationManager() setter.
I'm one of SVNKit developers if this matters.
Solution based on Dmitry Pavlenko's answer:
And this is the dependency in maven POM file: