Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.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 JGit克隆从gerrit失败,没有用户名或密码_Java_Git_Jgit - Fatal编程技术网

Java JGit克隆从gerrit失败,没有用户名或密码

Java JGit克隆从gerrit失败,没有用户名或密码,java,git,jgit,Java,Git,Jgit,我对JGit版本3.0.0.201306101825-r有问题。以下是我的克隆功能: public static void cloneRepository(String localRepositoryPath, String remoteRepositoryURI, String branch, String username, String password) throws IOException, InvalidRemoteException, GitAPIException { F

我对JGit版本3.0.0.201306101825-r有问题。以下是我的克隆功能:

public static void cloneRepository(String localRepositoryPath, String remoteRepositoryURI, String branch, String username, String password) throws IOException, InvalidRemoteException, GitAPIException {
    File workDir = createFolder(localRepositoryPath);
    CloneCommand clone = Git.cloneRepository();
    clone.setBare(false);
    clone.setCloneAllBranches(false);
    clone.setBranch(branch);
    clone.setDirectory(workDir).setURI(remoteRepositoryURI);
    if (StringUtils.isNotEmpty(username)) {
        UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(username, password);
        clone.setCredentialsProvider(credentials);
    }
    Git git = clone.call();
}
我正试图从gerrit克隆一个存储库,每个人都有权阅读它。”git克隆ssh://gerrit.xx.com:29418/project/test'从终端正常工作,但使用Jgit我无法克隆存储库。这是我得到的一个错误:

[INFO] [talledLocalContainer] Caused by: org.eclipse.jgit.errors.TransportException: ssh://gerrit.xx.com:29418/project/test: Auth fail
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:142) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:121) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:248) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:147) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1105) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   ... 55 more
[INFO] [talledLocalContainer] Caused by: com.jcraft.jsch.JSchException: Auth fail
[INFO] [talledLocalContainer]   at com.jcraft.jsch.Session.connect(Session.java:491) [jsch-0.1.49.jar:]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   ... 62 more
[INFO] [talledLocalContainer] 
[INFO][talledLocalContainer]由以下原因引起:org.eclipse.jgit.errors.TransportException:ssh://gerrit.xx.com:29418/project/test: 验证失败
[信息][talledLocalContainer]位于org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:142)[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.0.201306101825-r]
[INFO][talledLocalContainer]位于org.eclipse.jgit.transport.sshttransport.getSession(sshttransport.java:121)[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[信息][talledLocalContainer]位于org.eclipse.jgit.transport.TransportGitsh$SshFetchConnection.(transportGitsh.java:248)[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO][talledLocalContainer]位于org.eclipse.jgit.transport.transportGitsh.openFetch(transportGitsh.java:147)[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO][talledLocalContainer]位于org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO][talledLocalContainer]位于org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.0.201306101825-r]
[INFO][talledLocalContainer]位于org.eclipse.jgit.transport.transport.fetch(transport.java:1105)[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.0.201306101825-r]
[INFO][talledLocalContainer]位于org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128)[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.0.201306101825-r]
[信息][talledLocalContainer]。。。55多
[信息][talledLocalContainer]由以下原因引起:com.jcraft.jsch.JSchException:Auth fail
[INFO][talledLocalContainer]位于com.jcraft.jsch.Session.connect(Session.java:491)[jsch-0.1.49.jar:]
[信息][talledLocalContainer]位于org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116)[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.0.201306101825-r]
[信息][talledLocalContainer]。。。62多
[信息][talledLocalContainer]
如何解决这个问题的想法非常受欢迎

我认为git克隆ssh://gerrit.xx.com:29418/project/test 之所以有效,是因为它使用客户端maschine上的登录用户名,并对gerrit执行基于密钥的身份验证

通常,您不能使用ssh执行任何匿名通信。JGit可能不知道它的环境,您必须显式地提供用户名和适当的ssh密钥,特别是在启用ssh的用户上下文之外运行Java代码时。使用UsernamePasswordCredentialsProvider将无法使用ssh访问gerrit


我建议您使用HTTP对gerrit进行匿名读取访问。git克隆http://gerrit.xx.com:[port]/test应完成此工作。当[port]是gerrit安装侦听HTTP请求的端口时。我认为默认的ist 8080。

如果您没有使用像Eclipse这样具有适当支持的程序,您可以尝试将GIT_SSH设置为外部可执行文件来运行您的进程,这样可以代表您进行身份验证