2012-02-20 5 views
2

Appache Velocityに新しく、Eclipseで初めてのVMページを実行しようとしました(成功なし)。Eclipse + Apache Velocity Engine?

  1. はベロシティエンジンのディストリビューションをダウンロードしてください:ここで私はこれまでに撮影した段階だhttp://velocity.apache.org/download.cgi#Engine
  2. サーバー
  3. は単純なインデックスを作成してTomcatを選択してEclipseの
  4. をダイナミックWebプロジェクトを作成します。 WebContentフォルダー
  5. でVMファイルは私のプロジェクトのクラスパス
  6. 実行index.vmにvelocity-1.7.zipからすべてのjarファイルを追加し、(ない「VM-化さ」)であるとして、すべてのVTLを出力します。

index.vm:

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

すべてのヘルプは大歓迎です!

答えて

1

これはEclipseで動作しています。すべての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

あなたのベロシティプロジェクトの例を教えてください。私は1つを設定したいが、私は困難を抱えている。あなたはおそらく私のファイルがどこに行くか見ることができるようにあなたのプロジェクトのフォルダを共有できますか? ありがとう! – deucalion0

関連する問題