Setting known_hosts in jgit

Using jgit with gitolite for version control, I have an application that generates specific code in a command and that we want to bind to source control. The goal is to pull forward fast, commit a new code and then press it.

I have the following method:

private void commitToGitRepository(String updateComment, Config config)
      throws IOException, NoFilepatternException, GitAPIException
{
   if(git == null)
   {
      git = Git.open(new File(config.getDpuCheckoutDir()));
   }
   PullCommand pull = git.pull();
   pull.call();
}

This method fails when the method is called pull.call()with the following exception:

com.jcraft.jsch.JSchException: UnknownHostKey: www.somehost.com. RSA key fingerprint is 9d:92:a9:c5:5d:cb:5f:dc:57:ff:38:7e:34:31:fe:75
at com.jcraft.jsch.Session.checkHost(Session.java:748)
at com.jcraft.jsch.Session.connect(Session.java:319)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:121)
at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:248)
at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:147)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1104)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128)
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:245)
at net.intellidata.dpu.controller.schema.EntityMappingController.commitToGitRepository(EntityMappingController.java:149)
... (truncated where it meets my code)

As I read this, it seems that he did not find my known_hosts file in user_home/.git. However, I searched for an hour, and I find no way to configure JGit to tell JSch where to look for the known_hosts file.

Suggestions? I know that the entry for the source is in my known_hosts file

+5
source share
1

:

jsch.setKnownHosts("C:\\Users\\aUsername\\known_hosts");

jgit, jsch ( Java), :

C:\Users\VonC\prog\git>git clone https://github.com/eclipse/jgit
Cloning into 'jgit'...
remote: Counting objects: 37854, done.
remote: Compressing objects: 100% (7743/7743), done.
remote: Total 37854 (delta 22009), reused 34367 (delta 18831)
Receiving objects: 100% (37854/37854), 6.73 MiB | 1.37 MiB/s, done.
Resolving deltas: 100% (22009/22009), done.

C:\Users\VonC\prog\git>cd jgit

C:\Users\VonC\prog\git\jgit>grep -nrHI "setKnownHosts" *
org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java:262:                              sch.setKnownHosts(in);

!

JschConfigSessionFactory.java#knownHosts() :

new File(new File(home, ".ssh"), "known_hosts");
# with:
home = fs.userHome();

userHome System.getProperty( "user.home" ).

, java- user.home, %USERPROFILE%/.ssh/known_hosts.

(user.home java %USERPROFILE% Windows, , Windows: ).


, %USERPROFILE%/.ssh/known_hosts,

SSH ( ssh), ~/.ssh/known_hosts file.


StormeHawke :

Tomcat Windows, Jsch ( JGit) , SYSTEM .ssh.
.ssh SYSTEM, Tomcat (, , ).

, , LocalSystem Account :

C:\Documents and Settings\Default User
# or Wind7 / 2008
C:\Windows\System32\Config\systemprofile

:

:

 System.out.println(System.getProperty("user.home")); 

SYSTEM Windows7 (, , Windows NT) C:\.
( , ).

+7

All Articles