2016-10-07 12 views
1

Apache Batik을 사용하여 SVG를 프로젝트 중 하나에서 PDF로 변환합니다. 이 프로젝트는 Tomcat 7에서 실행되는 Spring 애플리케이션이다. $ CATALINA_HOME/bin/startup.sh를 사용하여 Tomcat을 시작하면서 Ubuntu에서 실행되는 개발 기계에서 모든 것이 정상적으로 작동한다. 하지만 CentOS 6와 함께 프로덕션 서버에서 앱을 실행하려고 시도하고 Tomcat이 service tomcat7 start 명령을 사용하기 시작하면 앱이 변환시 무한 루프에 빠지게됩니다. 나는 문제를 디버깅하기 위해 노력하고 코드의 조각을 발견했습니다 PDFDocumentGraphics2DConfigurator 클래스CentOS의 Apache FOP에서 글꼴 무한 검색

/** 
* Creates the {@link FontInfo} instance for the given configuration. 
* @param cfg the configuration 
* @param useComplexScriptFeatures true if complex script features enabled 
* @return the font collection 
* @throws FOPException if an error occurs while setting up the fonts 
*/ 
public static FontInfo createFontInfo(Configuration cfg, boolean useComplexScriptFeatures) 
    throws FOPException { 
    FontInfo fontInfo = new FontInfo(); 
    final boolean strict = false; 
    if (cfg != null) { 
     URI thisUri = new File(".").getAbsoluteFile().toURI(); 
     InternalResourceResolver resourceResolver 
       = ResourceResolverFactory.createDefaultInternalResourceResolver(thisUri); 
     //TODO The following could be optimized by retaining the FontManager somewhere 
     FontManager fontManager = new FontManager(resourceResolver, FontDetectorFactory.createDefault(), 
       FontCacheManagerFactory.createDefault()); 

     //TODO Make use of fontBaseURL, font substitution and referencing configuration 
     //Requires a change to the expected configuration layout 

     DefaultFontConfig.DefaultFontConfigParser parser 
       = new DefaultFontConfig.DefaultFontConfigParser(); 
     DefaultFontConfig fontInfoConfig = parser.parse(cfg, strict); 
     DefaultFontConfigurator fontInfoConfigurator 
       = new DefaultFontConfigurator(fontManager, null, strict); 
     List<EmbedFontInfo> fontInfoList = fontInfoConfigurator.configure(fontInfoConfig); 
     fontManager.saveCache(); 
     FontSetup.setup(fontInfo, fontInfoList, resourceResolver, useComplexScriptFeatures); 
    } else { 
     FontSetup.setup(fontInfo, useComplexScriptFeatures); 
    } 
    return fontInfo; 
} 

합니다. 개발자 컴퓨터에서 앱을 실행하면 결과는 thisUri이고 ~/tomcat/bin/. 폴더가 할당됩니다. 앱이 프로덕션 컴퓨터에서 실행될 때 /. 값이 할당됩니다. thisUri의 값은 FOP가 글꼴 검색을 시작하고 프로덕션 컴퓨터에서 이것이 파일 시스템의 루트이고 전체 FS 구조에서 재귀 검색이 매우 느리기 때문에 이것이 주요 문제라고 생각합니다. fop.xconf 파일을 글꼴 구성으로 WEB-INF 디렉토리에 추가하려고했지만 FOP의 동작에는 영향을 미치지 않았습니다. 그리고 나는 dev machine에서 시작하는 것과 같은 방식으로 Tomcat을 프로덕션 서버에서 시작할 수 없습니다. FOR의 글꼴 스캔을위한 기본 디렉토리를 구성하는 방법에 대한 아이디어가 있습니까? 아니면 내가 잘못하고있는거야?

답변

1

문제의 해결 방법을 발견했습니다. 나는 그것의 글이나 실수가 그런 것들을 할 수는 있지만 작동하는지 확실하지 않습니다. 해결 방법은 File.getAbsolutFile()user.dir 옵션으로 정의 된 디렉토리에 대해 확인 된 디렉토리를 반환한다는 사실을 기반으로합니다. 그래서 Tomcat 서비스 시작시이 옵션을 전달할 방법이 필요합니다. 내가 이것을 발견 한 유일한 방법은 %CATALINA_HOME/bin/setenv.sh 파일에 정의 된 CATALINA_OPTS 변수에 -Duser.dir=/%CATALINA_HOME/을 추가하는 것입니다. 그 후 글꼴 스캔 프로세스는 정상적인 시간이 걸렸고 내 응용 프로그램은 정상적으로 작동하기 시작했습니다.