Search code examples
javaapigithubnetbeansclassnotfoundexception

ClassNotFoundException on Github class - jcabi library


I'am using NetBeans to write a java application that would allow me to get the zip file of a GitHub user repository. In order to do that, I imported an external jar library, jcabi library, into the netbeans project that let me communicate with the GitHub API.

How I imported: right-click on the project -> properties -> libraries -> Add JAR/Folder

Then I start coding: I tried different constructors for the Github class (the root for communicating with the whole library), but always the same error.

enter image description here

I also tried with another .jar library: kohsuke -> same error.

And if it is not enought, I also tried with eclipse -> same error.

Now, I don't know what the problem could be:

  • Library importation? (When I write The Github class, netbeans shows me the possibility to import the class, so I don't think this could be the problem, but still...)
  • My usage of the Github constructor (Probably)
  • something else?

Solution

  • First make sure you download this jar file: jcabi-github-0.23-jar-with-dependencies.jar. It has all the dependencies you need. Which can be found here towards the end of the page.

    It is strongly recommended to use RetryWire to avoid accidental I/O exceptions:

    This compiled for me:

     Github github = new RtGithub(
     new RtGithub()
     .entry()
     .through(RetryWire.class)
    );
    

    Sample program:

     Github github = new RtGithub(
                     new RtGithub("yourUsername", "yourPassword")
                     .entry()
                     .through(RetryWire.class)
     );
    
     Repo repo = github.repos().get(
     new Coordinates.Simple("sebenalern/database_project"));
     Issues issues = repo.issues();
     Issue issue = issues.create("issue title", "issue body");
     issue.comments().post("issue comment");
    

    After running the above code it posted an issue in my repo with title as "issue title" the body as "issue body" and a comment as "issue comment"

    Hope this helps! Let me know if you need anything clarified or more examples. Note this code was tested.