2017-09-12 1 views
0

Project structure 위와 같이 프로젝트 구조. 코드에서, 이전Bundle-ClassPath에서 Velocity jar를 MANIFEST.MF의 Import-Package (Plugin dependancies)로 옮겼습니다. 그럼 .vm 파일의 위치는 무엇입니까?

/* Define velocity engine and template */ 
VelocityEngine ve = new VelocityEngine(); 
ve.setProperty("resource.loader", "classpath"); 
ve.setProperty("classpath.resource.loader.class",ClasspathResourceLoader.class.getName()); 
ve.init(); 
Template t = ve.getTemplate("fileTemplates/DCM_Default.vm"); 

은/lib 폴더에 존재하는 velocity.jar. 따라서, DCM_Default.vm는 found.MENIFEST.MF가 클래스 경로에 아래와 같은 항목

Bundle-ClassPath: ., lib 디렉토리/속도-1.7-dep.jar

이제 속도했습니다. 항아리 클래스 경로에서 제거하고 MENIFEST.MF에서 플러그인 의존성에 존재하는 변경 사항 -

Import-Package: org.apache.velocity, org.apache.velocity.app, org.apache.velocity.context, org.apache.velocity.exception, org.apache.velocity.runtime, org.apache.velocity.runtime.resource.loader

아래에있는 나는 내가 .vm 넣어야 할 경로를 찾을 수 없습니다 아래 예외 상황에 직면했기 때문에 발생 : org.apache.velocity.exception.ResourceNotFoundException : 'fileTemplates/DCM_Default.vm'리소스를 찾을 수 없습니다.

어떤 아이디어가 있습니까? 제발 제안 해주세요.

+0

예외가 분명히 경로를 찾지 못합니다. 'src' 폴더 안에'fileTemplates' 폴더를 옮길 수 있습니다. – soorapadman

+0

답장을 보내 주셔서 감사합니다. src /에있는 fileTemplates/DCM_Default.vm 폴더를 옮겼지만 작동하지 않았습니다. RCP를 클라이언트로 사용하고 있습니다. – Aditi

+0

Maven 프로젝트를 사용하고 있습니까? – soorapadman

답변

0

I을 발견 된 해답은 다음과 같다.

 //Define template location 
     Bundle bundle = FrameworkUtil.getBundle(getClass()); 
     URL fileUrl = FileLocator.toFileURL(FileLocator.find(bundle, new Path('fileTemplates/'), null));` 

     /* Define velocity engine and template */ 
     VelocityEngine ve = new VelocityEngine(); 
     ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, fileUrl.getPath()); 
     ve.init(); 
     Template t = ve.getTemplate("DCM_Default.vm"); 

경로에서 우리는 런타임에 계산하는 폴더의 절대 경로가 필요합니다. RCP 클라이언트 플러그인 프로젝트에서 작동합니다.

0

ClasspathResourceLoader를 사용하는 경우 런타임에 fileTemplates/DCM_Default.vm이 포함 된 jar가 있어야합니다. 그것을 src 디렉토리 밑에 두는 것이 classpath의 일부라는 것을 보장하지 않을 것이고, IDE에 달려있다. (어떤 문서가 그렇게해야하는지 알려줄 것이다.)

템플릿에 대한 절대 경로를 알고있는 경우 FileResourceLoader를 사용할 수도 있습니다.

0

당신은 메이븐 프로젝트 당신의 속도 파일 resources 폴더

을에 있어야합니다 그리고 난 항상 템플릿로드 구성 아래 사용 src-->main-->resources-->fileTemplates

처럼 구조가 있어야한다 준수 때문에 :

velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "class,file"); 
velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute"); 
velocityEngine.setProperty("runtime.log.logsystem.log4j.logger", "VELLOGGER"); 
velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); 
velocityEngine.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem"); 
관련 문제