0

我正在尝试在我的 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

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

4

1 回答 1

1

看来您缺少推送 SSH 所需的jsch库。将它添加到您的类路径中(如果您使用 Maven,请将其添加到您的 pom 中,或者将 jar 添加到您的类路径中)。

于 2012-07-12T18:47:28.583 回答