2017-07-26 75 views
0

我想用Ghost4j將一些PDF文件轉換成PNG文件。這個庫需要log4j的工作,所以我添加到我的庫也log4j。log4j不能在tomcat8服務器上使用log4j.properties文件

由於我的應用程序是動態Web項目,因此我將這些庫添加到文件夾WEB-INF/lib中。

當我試圖運行我的本地tomcat8服務器上的應用程序,它記錄了一些警告,比如:

log4j:WARN No appenders could be found for logger (org.ghost4j.Ghostscript). 
log4j:WARN Please initialize the log4j system properly. 
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 

所以,網上衝浪,我發現我不見了log4j.properties文件中我的應用程序。因此,我創建了文件log4j.properties並將其添加到WEB-INF/classes中(正如其他一些stackoverflow文章中所建議的那樣)。然後,使用此修復程序,我的位置tomcat8服務器上的應用程序運行平穩。

雖然,當我試圖將它部署在遠程tomcat8服務器上時,應用程序不起作用。問題在於它不會產生任何類型的異常,它只會中斷其工作。有或者沒有log4j.properties文件,在遠程tomcat8服務器上沒有區別:它只是停在與之前在本地服務器上記錄我之前編寫的警告相同的「代碼行」上運行。

任何幫助是apreciated。

P.S .:轉換代碼非常簡單。我發佈它來完成我的問題:

private void createImages(String machine, String fileName){ 
     LOGGER.warning("started creating images"); 
     try{ 
      PDFDocument document = new PDFDocument(); 
      document.load(new File(DOCS_DIR + machine + "/" + fileName + ".pdf")); 

      String commonPath = IMGS_DIR + machine + "/" + fileName + "/"; 
      Path path = Paths.get(new File(commonPath).getPath()); 
      if(Files.notExists(path, LinkOption.NOFOLLOW_LINKS)){ 
       new File(commonPath).mkdirs(); 
      } 
      SimpleRenderer renderer = new SimpleRenderer(); 
      renderer.setResolution(300); 
      renderer.setAntialiasing(SimpleRenderer.OPTION_ANTIALIASING_HIGH); 

      LOGGER.warning("IT STOPS HERE!!"); 
      List<Image> images = renderer.render(document); // this is the line in which the execution of the program stops.. 
      LOGGER.warning("pdf pages are: " + images.size()); 
      for (int i = 0; i < images.size(); i++) { 
       Image img = images.get(i); 
       Image scaledImg = img.getScaledInstance(1200, -1, Image.SCALE_SMOOTH); 
       BufferedImage newImage = new BufferedImage(scaledImg.getWidth(null), scaledImg.getHeight(null), BufferedImage.TYPE_INT_ARGB); 
       Graphics2D g = newImage.createGraphics(); 
       g.drawImage(scaledImg, 0, 0, null); 
       g.dispose(); 
       String extension = ".png"; 
       String imgName = commonPath + (i + 1) + extension; 
       LOGGER.warning("creating img n: " + (i+1) + " - creating img in folder: " + imgName); 
       ImageIO.write((RenderedImage) newImage, "png", new File(imgName)); 
      } 

      LOGGER.warning("finished creating images!"); 
     } catch(FileNotFoundException e){ 
      LOGGER.warning("ERROR DOCUMENT SERVICE -- FileNotFoundException"); 
      LOGGER.warning(e.printStackTrace()); 
     } catch (IOException e) { 
      LOGGER.warning("ERROR DOCUMENT SERVICE -- IOException"); 
      LOGGER.warning(e.printStackTrace()); 
     } catch (RendererException e) { 
      LOGGER.warning("ERROR DOCUMENT SERVICE -- RendererException"); 
      LOGGER.warning(e.printStackTrace()); 
     } catch (DocumentException e) { 
      LOGGER.warning("ERROR DOCUMENT SERVICE -- DocumentException"); 
      LOGGER.warning(e.printStackTrace()); 
     } catch (Exception e){ 
      LOGGER.warning("ERROR DOCUMENT SERVICE -- Exception"); 
      LOGGER.warning(e.printStackTrace()); 
     } 
    } 

回答

0

最後我自己找到了解決方案。

該問題與log4j無關,但無法正常工作,因爲它缺少服務器上的Ghostscript。

在服務器上安裝Ghostscript後,一切工作正常。

相關問題