如何在eclipse或netBeans中修复NoClassDefFoundError?

时间:2015-04-11 14:25:50

标签: java eclipse noclassdeffounderror

大家好我用eclipse编写我的java项目并在eclipse中运行但是我收到错误,这是我的代码:

package first;
import com.hp.hpl.jena.reasoner.rulesys.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.ontology.*;
import java.io.*;
//import com.hp.hpl.jena.
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import java.util.*;
/**
 *
 * @author Zara-t
 */
public class First {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("hi");
        First test=new First();
        test.start();
    }
    private Model model;

    public void start(){
        String file = "D:\\arshad-comp\\terme2\\expertSys\\food.owl";
         // create an empty model
         Model model = ModelFactory.createDefaultModel();

         // use the FileManager to find the input file
         InputStream in = FileManager.get().open( file );
        if (in == null) {
            throw new IllegalArgumentException(
                                         "File: " + file + " not found");
        }

        // read the RDF/XML file
        model.read(in, null);

        // write it to standard out
        model.write(System.out);
    }
}

我的项目位于c:\ wamp \ www \ projectFolder中,我添加到项目中的库位于此路径中D:\ arshad-comp \ terme2 \ expertSys \ protege-5.0.0-beta-15 \ Protege_5 .0_beta \ test \ bin这是我的类路径内容

<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="lib" path="D:/arshad-comp/terme2/expertSys/protege-5.0.0-beta-15/Protege_5.0_beta/jena.zip"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

这是错误行:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at com.hp.hpl.jena.rdf.model.impl.PropertyImpl.<clinit>(PropertyImpl.java:61)
    at com.hp.hpl.jena.enhanced.BuiltinPersonalities.<clinit>(BuiltinPersonalities.java:27)
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.<init>(ModelCom.java:51)
    at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:125)
    at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:119)
    at first.First.start(First.java:35)
    at first.First.main(First.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    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)
    ... 7 more
Java Result: 1

我真的不知道该怎么做:(我不记得我改变了什么。我的代码工作1天前我在互联网上做任何解决方案 请帮帮我

1 个答案:

答案 0 :(得分:0)

jena在运行时需要LogFactory类,你可以在jena pom中看到对日志库here的依赖,添加一个日志实用程序库将修复那个.Class:LogFactory在commons-logging你可以从它下载它here