Johannes Beutel
Johannes Beutel

Reputation: 1

jGit push produces exception

I am trying to use jGit in my java project. The version I am using is "2.0.0.201206130900-r" and my OS is Windows. everything worked fine until i tried to do a push:

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();
}
  }

what i get is the following:

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

Can pls someone tell me what is wrong in my code?

Upvotes: 0

Views: 2131

Answers (1)

robinst
robinst

Reputation: 31417

It seems you are missing the jsch library which is needed for pushing over SSH. Add it to your classpath (add it to your pom if you're using Maven or add the jar to your classpath).

Upvotes: 1

Related Questions