使用jgit的Java git客户端 [英] Java git client using jgit

查看:261
本文介绍了使用jgit的Java git客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用java编写的git客户端遇到了一些困难。我正在使用jGit库通过git服务器上的ssh进行连接。问题是我不知道如何指定私钥的路径和密码。我在jGit文档中找不到有关我需要调用的函数的任何示例。从我读到的jGit库使用JSch使用ssh连接到服务器,JSch支持私钥和密码。有没有人有这方面的经验或有一些工作代码?

I am having some difficulties with a git client written in java. I am using the jGit library to connect through ssh on the git server. The problem is that i don't know how to specify the path to the private key and the passphrase for it. I couldn't find any examples in the jGit documentation about what functions i need to call. From what i read the jGit library is using JSch to connect to the server using ssh and JSch supports private keys and passphrases. Does anyone have any experience with this or has some working code?

谢谢

推荐答案

我没有使用jGit,但是从查看Javadocs(看似不在线浏览,但可以下载) )您需要配置SshSessionFactory(即创建JSchConfigSessionFactory的子类,并覆盖其 configure 方法)。

I didn't ever use jGit, but from looking at the Javadocs (which are seemingly not online browsable, but can be downloaded) you need to configure a SshSessionFactory (i.e. create a subclass of JSchConfigSessionFactory, and override its configure method).

JSch 对象支持带有 addIdentity 方法的私钥,密码可以用 UserInfo 对象每个JSch 会话

The JSch object supports private keys with its addIdentity methods, and the passphrases can be given with UserInfo objects to each individual JSch Session.

(免责声明:JSch Javadoc是我写的。)

这篇关于使用jgit的Java git客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆