2012-02-20 4 views
2

Appache Velocity를 처음 접했고 Eclipse에서 첫 번째 VM 페이지를 실행하려고 시도했습니다 (성공하지 못함). 여기에 지금까지 촬영 한 단계는 다음과 같습니다 Eclipse + Apache Velocity Engine?

  • 간단한 인덱스 만들기 서버로 Tomcat을 선택 이클립스
  • 에서 만들기 동적 웹 프로젝트를 http://velocity.apache.org/download.cgi#Engine
  • :
    1. 는 속도 엔진 배포를 다운로드합니다. 의 WebContent 폴더
    2. 에서 VM 파일 내 프로젝트 클래스 경로
    3. 실행 index.vm에 velocity-1.7.zip의 모든 jar 파일을 추가 (안 "VM화된")와 같이 모든 VTL을 출력합니다.

    index.vm은 :

    <html> 
    <body> 
    #set($foo = "Velocity") 
    Hello $foo World! 
    </body> 
    <html> 
    

    어떤 도움이 크게 감사합니다!

  • 답변

    1

    이클립스에서 작동하고 있습니다. 모든 Velocity Jar 파일을 Dynamic Web Project의 WEB-INF 폴더의 lib 디렉토리에 추가하기 만하면됩니다. 그런 다음 web.xml을 다음과 같이 업데이트하십시오.

    <?xml version="1.0" encoding="UTF-8"?> 
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
        <display-name>Velocity_Test</display-name> 
        <welcome-file-list> 
        <welcome-file>index.vm</welcome-file> 
        <welcome-file>index.html</welcome-file> 
        <welcome-file>index.htm</welcome-file> 
        <welcome-file>index.jsp</welcome-file> 
        <welcome-file>default.html</welcome-file> 
        <welcome-file>default.htm</welcome-file> 
        <welcome-file>default.jsp</welcome-file> 
        </welcome-file-list> 
    
        <!-- Define Velocity template compiler --> 
        <servlet> 
        <servlet-name>velocity</servlet-name> 
        <servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class> 
        </servlet> 
    
        <!-- Map *.vm files to Velocity --> 
        <servlet-mapping> 
        <servlet-name>velocity</servlet-name> 
        <url-pattern>*.vm</url-pattern> 
        </servlet-mapping> 
    </web-app> 
    
    +1

    부가 기능 관련 질문 lib 폴더에서 jar 파일을 제거하고 대신 클래스 경로에 추가했습니다. 그것은 많은 실수를 던졌습니다. 외부에서 모든 Velocity Jar 파일을 가리킬 수 있습니까, 아니면 이것을 작동시키기 위해 프로젝트의 lib 폴더로 파일을 가져와야합니까? 감사! – worked

    +0

    속도 프로젝트의 예를 들어 주시겠습니까? 나는 하나를 세우고 싶지만 어려움을 겪고 있습니다. 파일을 어디서 볼 수 있도록 프로젝트 폴더를 공유 할 수 있습니까? 감사합니다. – deucalion0

    관련 문제