1

i am not able to run my data analysis servlet. i get always this error:

    > javax.servlet.ServletException: Servlet execution threw an exception
    > root cause
    > 
    > java.lang.NoClassDefFoundError: weka/core/Attribute
    >   de.project.prediction.Predictor.<init>(Predictor.java:34)
    >   de.project.tests.AbfrageZulassungsberechnung.doPost(AbfrageZulassungsberechnung.java:56)
    >   javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    >   javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

It seems to be a classpath problem, but i added the JAR file weka.jar in the build path and its in the WEB-INF/lib folder of my servlet project.

The Predictor class contains this code:

            import java.util.ArrayList;
            import weka.classifiers.Classifier;
            import weka.core.Attribute;

    public class Predictor {
        private Formulardata formulardata = new Formulardata();
        public double result = 0;
    // Konstruktor
        public Predictor() throws Exception{
            ArrayList<Attribute> attribute = new ArrayList<Attribute>(29); // 29

    ArrayList<String> land = new ArrayList<String>();
    landHZB.add("fehlerhaft");
    landHZB.add("Schleswig-Holstein");
    landHZB.add("Hamburg");
    landHZB.add("Niedersachsen");
    landHZB.add("Bremen");
    landHZB.add("Nordrhein-Westfalen");
    landHZB.add("Hessen");
    landHZB.add("Rheinland-Pfalz");
    landHZB.add("Baden-Württemberg");
    landHZB.add("Bayern");
    landHZB.add("Saarland");
    landHZB.add("Berlin");
    landHZB.add("Brandeburg");
    landHZB.add("Mecklenburg-Vorpommern");
    landHZB.add("Sachsen");
    landHZB.add("Sachsen-Anhalt");
    landHZB.add("Thüringen");
    attribute.add(new Attribute("Land", land));
}
}

My System is an Eclipse IDE with a integrated Tomcat7 with OS Ubuntu 14.04

If i run this java file as an java project it seems to work. What i am doing wrong? Thanks for your help!

1 Answers1

1

I think your library is missing(weka.core.Attribute). Right click on your project --- > Deployment Assembly --> Add --> Archive from file system (if your using external jar file). Once you added clean your project and rerun it.

Sas
  • 2,473
  • 6
  • 30
  • 47
  • Thanks for your help. Now it works =) But I dont understand why a normal Java Application works if i just include the WEKA.jar in the buildpath but a servlet needs to add the JAR also in the Deployment Assembly? Do you have any hint where can i find more information about this problem? I would like to understand my fault... – SheldonCooper Nov 29 '14 at 20:06
  • Normal application runs inside your eclipse itself, whereas Webapps is deployed in a tomcat server as a war file. Thus your lib will not be available when you deploy it. So you need to add them manually. Take a look at [here](http://stackoverflow.com/questions/11126044/difference-between-deployment-assembly-and-j2ee-module-dependencies-in-eclipse) – Sas Nov 29 '14 at 20:52