Question

I am doing a project in java and all things were working great until i tried to run my program from the jar file. I managed to locate the problem and it goes like this:

I tried to implement a plug-in based methodology. I have a conf file from where i read the paths for the classes i want to use, and then i load them dynamically with class.forname. This is my code if it helps:

        for (i=0; i<classPathsArray.size(); i++) {
            Class c = Class.forName(classPathsArray.get(i));  //error line
            Object class2Add = (LibraryWrapper)c.newInstance();

            wrappers.add((LibraryWrapper)class2Add);
        }

the library paths are something like: "path.path.path.path.className" and they seem ok either i run my project from an IDE or from the jar (when i am saying "seem ok" i mean that they are exactly what is written to the file).

I indicate the exact line that creates the exception and here is a snapshot of the exception i get: enter image description here

I emphasize (again) that things are ok when execute my project from IDE, the problem is when i run it from jar which is in the dist folder.

Does anyone know why i have this problem and how to fix it?


PS: All my classes are in the "Source Packages" Folder

Was it helpful?

Solution

NoClassDefFoundError occurs due to incomplete classpath. Make sure all your required jars are in classpath before running jar file. If you are creating an executable jar file then you can define your classpath in manifest file something like this:

Class-Path: servlet.jar infobus.jar

Hope this helps.

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