3

I've got some troubles probably with adding correctly java libs into my Java EE project. I'm using intellij idea IDE.

I want to use an external library in my project (apache jena) and I've added that library using this procedure: Project Structure > Modules > Dependencies > Add JARs or dirs > Select apache jena lib dir (there are some .jar files inside, like core ..).

In the project, everything seems to be ok - import, object definitions .. But after deploy on the local glassfish server and after visiting index page, I got NoClassDefFoundError (exactly java.lang.NoClassDefFoundError: org/apache/jena/rdf/model/ModelFactory).

package controller;


import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import org.apache.jena.rdf.model.*;


@WebServlet( name = "TestController", urlPatterns = {"/"})
public class TestController extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET and POST methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        /* ERROR >> */
        Model model = ModelFactory.createDefaultModel();
        /* << ERROR */

        request.setAttribute("test", "test");
        request.getRequestDispatcher("test.jsp").forward(request,response);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

}

So can anyone advise me how to solve it, please? Thanks!

Crylvarrey
  • 109
  • 2
  • 6

1 Answers1

2

Problem solved: I had to add the library into the artifact (war exploded).

Procedure: Project structure > Artifacts > and there was a notice about missing library in that artifact so I clicked "Fix(add that library into the artifact)" > apply and Done :)

Intellij IDEA v14.1.5

Crylvarrey
  • 109
  • 2
  • 6