-4

As a result of my previous question I followed these steps to include Apache PDFbox without maven:

  1. downloaded .jars from download site of PDFbox (all under Libraries of each subproject)
  2. downloaded .jars from dependencies of PDFbox from maven repository (commons-logging and fontbox, but fontbox was already included in step 1)
  3. placed the downloaded .jars in a folder (C:\PDFjars)
  4. configured build path in eclispe (added all .jars as external libraries) It now looks like this: enter image description here

My servlet:

package servlets;
// other imports    
import org.apache.pdfbox.pdmodel.PDDocument;

@WebServlet("/print")
public class PrintServlet extends HttpServlet {
    public PrintServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // From a PDFbox Tutorial

        //Creating PDF document object 
          PDDocument document = new PDDocument();    

          //Saving the document
          document.save("C:/PdfBox_Examples/my_doc.pdf");

          System.out.println("PDF created");  

          //Closing the document  
          document.close();

        doGet(request, response);
    }

}

So when I start my web project and call the function the should produce a simple PDF document, I get folloing error:

    Servlet.service() for servlet [servlets.PrintServlet] in context with path [/StaticsCalculator] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.apache.pdfbox.pdmodel.PDDocument
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    at servlets.PrintServlet.doPost(PrintServlet.java:44)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

Solution: I had to copy the .jars in WEB-INF/lib folder as well.

Kinaeh
  • 277
  • 6
  • 16
  • You may want to check this : https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html – Arnaud Feb 19 '18 at 14:55
  • There's a "download" section on that website... – f1sh Feb 19 '18 at 14:55
  • 1
    *where there is a HTTP proxy preventing my eclipse* why you do not add the Proxy Settings in eclipse? – Jens Feb 19 '18 at 14:56
  • You might want to look at [How do I use Maven through a proxy?](https://stackoverflow.com/questions/1251192/how-do-i-use-maven-through-a-proxy) – Mark Rotteveel Feb 19 '18 at 14:56
  • 1
    Are you the only Java developer in your company? What do other developers do? It is actually not uncommon that MavenCentral is blocked, but then I would set up a company Nexus/Artifactory to provide the developers with the necessary artifacts. – J Fabian Meier Feb 19 '18 at 15:58
  • @JFMeier yes I am the only Java Developer and actually I'm hired for something else. (programming stuff for the ERP system) therefore my lck of knowledge in this field. – Kinaeh Feb 19 '18 at 16:35

2 Answers2

1

You can a) use a local maven repository and place the dependencies there. b) add the dependencies in the classpath of the application - that's basically what maven does for you.

Andreas Hartmann
  • 1,825
  • 4
  • 23
  • 36
1

Download the jar file by itself and add it to your code dependency. You can search for any Maven file on Maven Repository. If you're using Eclipse, just modify the build path to point to an external jar and give it the location of your jar. This will not take care of any dependencies your library requires, which leads into dependency hell where you'll have to read the pom and download each library manually.

Yserbius
  • 1,375
  • 12
  • 18