I am trying to clone a git project with Java over ssh. I have username and password of a git-shell user as credentials. I can clone the project in terminal using the following command with no problem. (Of course, it asks for the password first)
git clone user@HOST:/path/Example.git
However when I try the following code using JGIT api
File localPath = new File("TempProject");
Git.cloneRepository()
.setURI("ssh://HOST/path/example.git")
.setDirectory(localPath)
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("***", "***"))
.call();
I got
Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: ssh://HOST/path/example.git: Auth fail
What should I do? Any ideas? (I am using OSX 10.9.4 and JDK 1.8)
http
for git repo URI if you want to use Username and password as credential provider. – Coadjutress