Java NoClass Found Error

439 Views Asked by At

I'm trying to use Bliki to access and parse wiki pages. I just downloaded the zip file and put the bliki-core-3.0.19.jar into my eclipse build path.

However, when I tried to connect using sample code. there was an error. The sample code is here:

public static void test(){
    String pageName = "File:Mona Lisa.jpg";
    User user = new User("", "", "http://en.wikipedia.org/w/api.php");
    Connector con = new Connector();
    user = con.login(user);
    List<Page> pages = user.queryImageinfo(new String[]{pageName});
    if(pages != null)
        System.out.println(pages.size());
}

And I got errors as:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethod
at info.bliki.api.User.<init>(User.java:98)
at info.bliki.api.User.<init>(User.java:71)
at main.wiki.WikiCall.test(WikiCall.java:23)
at main.wiki.WikiCall.main(WikiCall.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpMethod
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 4 more

It seems like I'm missing the http jar for the connection, but there's no one the zip file and i thought the bliki-core.jar should contain it.

Any suggestions?

2

There are 2 best solutions below

0
On

This issue is that even once you have added HttpClient you will likely get other errors as the Bliki library depends on a number of 3rd party libraries.

If you are not familiar with the Maven build tool it may be worth having a look as one feature is that it will transitively resolve dependencies.

As a quick start:

In Eclipse do:

  1. File > New > Other > Maven Project

  2. Select the 'Create Simple Project' checkbox.

  3. Enter my.bliki.project as the group id and bliki-test as the Artifact id.

  4. Replace the contents of the generated pom.xml with the below.

  5. Right click on the project and select 'Maven > Update project.

You now have a project with Bliki and all 3rd p;arty dependencies on the buildpath (expand the Maven Dependencies folder to see what they are).

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.bliki.project</groupId>
    <artifactId>bliki-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>info.bliki.wiki</groupId>
            <artifactId>bliki-core</artifactId>
            <version>3.0.19</version>
        </dependency>
    </dependencies>

</project>
0
On

I'm not familiar with Bliki but from your stacktrace it looks like you are missing the Http Client from Apache Commons.

You should add the jar to your project and that should solve the problem.

Get the jar from here: http://hc.apache.org/