jGit push产生异常

时间:2012-07-12 16:39:26

标签: exception push jgit

我正在尝试在我的java项目中使用jGit。我使用的版本是“2.0.0.201206130900-r”,我的操作系统是Windows。一切正常,直到我试图推动:

public static void main(String[] args) {

    File gitDir = new File("c:\\new-repo\\");

try {

      String localPath = "c:\\new-repo\\";
      Repository localRepo = new FileRepository(localPath + ".git");
      localRepo.create();
      Git git = new Git(localRepo);

      git.add().addFilepattern("c:\\test.txt").call();

      git.commit().setMessage("testcommit").call();

      git.push().call();

  localRepo.close();
} catch (IllegalStateException ise) {
        System.out.println("The repository already exists!");
} catch (IOException ioe) {
        System.out.println("Failed to create the repository!");
} catch (NoFilepatternException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (GitAPIException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
  }

我得到的是以下内容:

Exception in thread "main" java.lang.NoClassDefFoundError: com/jcraft/jsch/JSchException
at org.eclipse.jgit.transport.Transport.<clinit>(Transport.java:111)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:141)
at Application.main(Application.java:76)
Caused by: java.lang.ClassNotFoundException: com.jcraft.jsch.JSchException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 3 more

有人可以告诉我我的代码有什么问题吗?

1 个答案:

答案 0 :(得分:1)

您似乎错过了推送SSH所需的jsch库。将它添加到类路径中(如果您正在使用Maven或将jar添加到类路径中,请将其添加到您的pom中。)