Question

I hope the answer will be stupidly simple, but I cannot get the following test program running due to a classnotfound exception:

import java.net.URL;

import net.sourceforge.spnego.SpnegoHttpURLConnection;

public class HelloKeytab {

    public static void main(final String[] args) throws Exception {
        System.setProperty("java.security.krb5.conf", "krb5.conf");
        System.setProperty("sun.security.krb5.debug", "true");
        System.setProperty("java.security.auth.login.config", "login.conf");

        SpnegoHttpURLConnection spnego = null;

        try {
            spnego = new SpnegoHttpURLConnection("spnego-client");
            spnego.connect(new URL("http://as1.test.local/hello_spnego.jsp"));

            System.out.println("HTTP Status Code: " 
                    + spnego.getResponseCode());

            System.out.println("HTTP Status Message: "
                    + spnego.getResponseMessage());

        } finally {
            if (null != spnego) {
                spnego.disconnect();
            }
        }
    }
}

I installed JDK7 and set the JAVA_HOME environment variable as an Administrator. I am working on a Windows XP machine as a regular domain user while compiling and running.

I have the spnego-r7.jar in the same directory as the HelloKeytab.java and I compiled with:

javac -cp .;spnego-r7.jar HelloKeytab.java 

which succesfully creates the class.

When I run the program with:

java -cp .;spengo-r7.jar HelloKeytab

I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: net/sourceforge/spneg
o/SpnegoHttpURLConnection
        at HelloKeytab.main(HelloKeytab.java:15)
Caused by: java.lang.ClassNotFoundException: net.sourceforge.spnego.SpnegoHttpUR
LConnection
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 1 more

The spnego-r7.jar can be found here: http://sourceforge.net/projects/spnego/files/

What I am doing wrong that it doesn't find my class?

Was it helpful?

Solution

NoClassDefFoundError are always because of incorrect or incomplete builds, or errors in class path.

I always go through the following checklist when getting this error:

  • Clean project
  • Check files and directories
  • Check build path

Try again. Never fails. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top