1

jGitの機能をテストするために単純なJavaクラスを試しています(以下を参照)。

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

ビルドパスに最新のjgitjarを使用してEclipseIndigoでこれを実行すると、「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 に答える