简单测试中的NoClassDefFoundError

时间:2013-07-08 03:32:51

标签: java object-object-mapping

我想使用moo进行dto-实体转换。但测试它我得到这个例外

    Exception in thread "main" java.lang.NoClassDefFoundError: org/mvel2/PropertyAccessException
    at com.codiform.moo.configuration.Configuration.getTranslator(Configuration.java:62)
    at com.codiform.moo.session.TranslationSession.getTranslator(TranslationSession.java:131)
    at com.codiform.moo.session.TranslationSession.translate(TranslationSession.java:122)
    at com.codiform.moo.session.TranslationSession.getTranslation(TranslationSession.java:64)
    at com.codiform.moo.curry.Translate.from(Translate.java:63)
    at Main.main(Main.java:15)
Caused by: java.lang.ClassNotFoundException: org.mvel2.PropertyAccessException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 6 more

是因为我做错了吗?这是我的代码:

import com.codiform.moo.curry.Translate;


public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
Guld guld1=new Guld("string from guld", "muck around", 5);
GuldDTO guld1DTO;
GuldDTO testclassload = new GuldDTO("ruks","halim",3);

guld1DTO=Translate.to(GuldDTO.class).from(guld1);
        //Beca beca1 = new Beca ()

System.out.println(guld1);
System.out.println(guld1DTO);
    }

}

public class Guld {

    private String fielk1;
    private String rupo;
    private Integer higs;
    public Guld(){

    }
    public Guld(String fielk1, String rupo, Integer higs) {

        this.fielk1 = fielk1;
        this.rupo = rupo;
        this.higs = higs;
    }
    public String getFielk1() {
        return fielk1;
    }
    public void setFielk1(String fielk1) {
        this.fielk1 = fielk1;
    }
    public String getRupo() {
        return rupo;
    }
    public void setRupo(String rupo) {
        this.rupo = rupo;
    }
    public Integer getHigs() {
        return higs;
    }
    public void setHigs(Integer higs) {
        this.higs = higs;
    }


}

public class GuldDTO {
    private String fielk1;
    private String rupo;
    private Integer higs;
    public GuldDTO (){

    }
    public GuldDTO(String fielk1, String rupo, Integer higs) {

        this.fielk1 = fielk1;
        this.rupo = rupo;
        this.higs = higs;
    }
    public String getFielk1() {
        return fielk1;
    }
    public void setFielk1(String fielk1) {
        this.fielk1 = fielk1;
    }
    public String getRupo() {
        return rupo;
    }
    public void setRupo(String rupo) {
        this.rupo = rupo;
    }
    public Integer getHigs() {
        return higs;
    }
    public void setHigs(Integer higs) {
        this.higs = higs;
    }

}

如果有任何其他细节我应该提供请告诉。 [显然我无法通过检查代码与文本比率的stackoverflow过滤器。] [完成]

3 个答案:

答案 0 :(得分:2)

ClassNotFoundException excption表示缺少类为此类添加库并再次运行。 首先检查你的apllication是否有这个类,否则添加mvel lib。

位于:http://grepcode.com/snapshot/repo1.maven.org/maven2/org.mvel/mvel2/2.1.4.Final/

答案 1 :(得分:0)

当您对该类具有依赖性时,您会看到java.lang.NoClassDefFoundError,并且它不在您项目的依赖项列表中。

所以,你需要做的是:

org.mvel2.PropertyAccessException类的jar添加到您的项目外部

罐子可用here

答案 2 :(得分:0)

正如其他人已经说过的那样,你缺少一个类文件,你需要在classpath中添加所需的jar文件。为了检查类的加载方式和位置,您可以将-verbose:class传递给java exe。这将显示程序运行时加载的类的跟踪。用于调试此类问题。