1

我正在尝试一个简单的 java 类来测试 jGit 的功能(见下文)。

import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;

import java.io.File;
import java.io.IOException;


public class CreateRepository {
   public static void main( String[] args ){
       Repository myrepo = createRepository("/mypath");
   }
public static Repository createRepository(String repoPath) {

        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repo = null;
        try {
            repo = builder.setGitDir(new File(repoPath))
              .readEnvironment() // scan environment GIT_* variables
              .findGitDir() // scan up the file system tree
              .build();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    return repo;
}
}

当我在构建路径中使用最新的 jgit jar 在 Eclipse Indigo 上运行它时,我收到错误消息“需要 2 个参数”——没有别的,没有例外!:S

感谢您提前提供任何帮助。

4

2 回答 2

1

首先查看包 org.eclipse.jgit.api。最简单的开始是从 Git 类开始:

// clone a repository
Git git = Git.cloneRepository().setURI("git://yourserver/repo.git").call();

// init a fresh new repository in the current directory
Git git = Git.init().call();

// open a repository on your disk
Git git = Git.open(new File("/path/of/repo");

然后探索从这些起点获得的 git 对象上可用的命令。

于 2012-08-23T18:00:06.210 回答
1

JGit 中唯一显示该错误消息的部分是在main() 函数中MyersDiff

/** 
 * @param args two filenames specifying the contents to be diffed
 */
public static void main(String[] args) {
  if (args.length != 2) {
    System.err.println(JGitText.get().need2Arguments);
    System.exit(1);
  }
  // ...
}

所以检查你的类路径并确保你的项目(和你的main())在 jgit.jar之前,并且你不会以某种方式调用错误的main().

于 2012-08-18T08:25:19.503 回答