Error when running helloworld + classpath problem

I am compiling helloworldapp with no errors.

I am running java helloworldapp on windows

CLASSPATH: .;C:Program FilesJavajre7lib;

JAVA_HOME: C:Program FilesJavajre7

path includes C:Program FilesJavajdk1.7.0bin


C:UserskDesktopabcl-bin-0.26.2>java helloworldapp
Exception in thread "main" java.lang.NoClassDefFoundError: helloworldapp (wrong
name: HelloWorldApp)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at Source)

So ok, for some reson it couldn’t find the classes, so I am trying to do it manually.

C:UserskDesktopabcl-bin-0.26.2>java -cp "C:Program FilesJavajre7lib" helloworldapp
Error: Could not find or load main class helloworldapp

C:UserskDesktopabcl-bin-0.26.2>java -cp C:Program FilesJavajre7lib; helloworldapp
Error: Could not find or load main class FilesJavajre7lib;

What am I doing wrong? I have looked at several forums, but they weren’t particularly helpful.

Update, I got past the helloworld stage. Now the real problem

import org.armedbear.lisp.*;

public class Main

    public static void main(String[] argv)
        Main thisObject = new Main();
        Interpreter interpreter = Interpreter.createInstance();
        interpreter.eval("(load "lispfunctions.lisp")");
        org.armedbear.lisp.Package defaultPackage = 
        Symbol voidsym = 
        Function voidFunction = (Function) voidsym.getSymbolFunction();
        voidFunction.execute(new JavaObject(thisObject));
    catch (Throwable t)
    public int addTwoNumbers(int a, int b)
    return a + b;

I tried both

C:UserskDesktopabcl-bin-0.26.2>java -cp abcl.jar Main
Error: Could not find or load main class Main

C:UserskDesktopabcl-bin-0.26.2>java -cp abcl.jar main
Error: Could not find or load main class main

The abcl.jar is located in the same folder

Some more trials and errors

C:UserskDesktopabcl-bin-0.26.2>java -cp .:abcl.jar Main
Error: Could not find or load main class Main

C:UserskDesktopabcl-bin-0.26.2>java Main -cp .:abcl.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/armedbear/lisp/Li
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.armedbear.lisp.LispObject
        at$ Source)
        at$ Source)
        at Method)
        at Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 6 more


When you write a class in java, the name of the file must match the name of the class.

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello world");


must be saved as
It must match the case i.e. would not work.

When you need to run the class, you must refer to it using the correct case.

java HelloWorldApp

but not

java helloworldapp

If you are referencing a JAR then you need to add it to your classpath. By default the classpath consists of the files in the current working directory. On windows the classpath is a semi-colon (;) separated list, on Linux and Mac OSX it is a colon (:) separated list.

To include the JAR in the classpath you must run the following…

java -cp .:myjar.jar MyMainClass

where myjar.jar is the JAR file you want to reference and MyMainClass is the class that contains your public static void main method.

Leave a Reply

Your email address will not be published. Required fields are marked *