2010-02-16 173 views
32

我正在使用maven2,如何向JSTL(JSP標準標記庫)添加依賴項?包含JSTL對Maven的依賴關係

+0

版本1.1.2,版本1.2,Tomcat和GlassFish之間有一個微妙之處。詳情請看這裏:http://tshikatshikaaa.blogspot.nl/2012/07/how-to-add-jslt-taglibs-in-maven-project.html – JVerstry 2012-07-27 17:55:44

回答

31

您需要將其添加到您的pom.xml文件中。

在依賴關係節點中,您需要添加對JSTL的引用。您可能需要將其範圍設置爲編譯。因此,這將是這個樣子

<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>jstl</artifactId> 
    <version>"whatever version you need"</version> 
    <scope>runtime</scope> 
</dependency> 

這是假設你在你的pom.xml或settings.xml中的行家分佈存儲庫中的適當引用

+0

這是否也包括'standard.jar'?我正在使用GlassFish,應該只包括'jstl'依賴項工作? – 2016-02-10 18:41:15

33

上面提到的依賴關係是不夠的,我(使用Tomcat 5.x作爲servlet容器,它本身不提供JSTL實現)。它只是將相應的JSTL接口包導入到項目中,並會在Tomcat中導致運行時錯誤。

這裏是我的項目中使用的依賴項部分,希望可以幫助別人。最難的部分是存儲庫中Apache的JSTL實現的命名。

<dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.1.1</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>taglibs</groupId> 
     <artifactId>standard</artifactId> 
     <scope>runtime</scope> 
     <version>1.1.1</version> 
    </dependency> 
    <dependency> 
     <groupId>taglibs</groupId> 
     <artifactId>c</artifactId> 
     <version>1.1.1</version> 
     <scope>runtime</scope> 
     <type>tld</type> 
    </dependency> 
    <dependency> 
     <groupId>taglibs</groupId> 
     <artifactId>fmt</artifactId> 
     <version>1.1.1</version> 
     <scope>runtime</scope> 
     <type>tld</type> 
    </dependency> 
+0

什麼是tld類型? – dcompiled 2012-02-04 05:29:47

+0

@dcompiled我沒有從Maven上找到這方面的官方文檔,但對於我的猜測,tld代表「標籤庫描述符」,它本身就是XML文件。 – 2012-02-04 07:00:59

+0

爲記錄,我使用tomcat 7和在接受的答案中給出的一個似乎已經足夠我... – eis 2012-08-22 12:30:59

1

我有同樣的問題。我通過將Apache Tomcat庫添加到Java構建路徑來解決此問題。

見我的截圖,我使用Maven:

增加Tomcat的庫之前:

desc

加入Tomcat的庫後:

desc

1

來源: apache taglib

 <!-- TAGLIB: --> 
      <dependency> 
      <groupId>org.apache.taglibs</groupId> 
      <artifactId>taglibs-standard-spec</artifactId> 
      <version>1.2.1</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.taglibs</groupId> 
      <artifactId>taglibs-standard-impl</artifactId> 
      <version>1.2.1</version> 
     </dependency> 
      <!-- From taglib doc: To use this distribution with your own web applications, add the following JAR 
       files to the '/WEB-INF/lib' directory of your application: 
        - taglibs-standard-spec-1.2.1.jar 
        - taglibs-standard-impl-1.2.1.jar 
        - taglibs-standard-jstlel-1.2.1.jar 
        - xalan-2.7.1.jar 
        - serializer-2.7.1.jar 
      --> 
     <dependency> 
     <groupId>xalan</groupId> 
     <artifactId>xalan</artifactId> 
     <version>2.7.1</version> 
    </dependency> 

     <dependency> 
     <groupId>xalan</groupId> 
     <artifactId>serializer</artifactId> 
     <version>2.7.1</version> 
    </dependency> 
    <!-- TAGLIB: --> 
0
<!-- standard.jar --> 
<dependency> 
    <groupId>taglibs</groupId> 
    <artifactId>standard</artifactId> 
    <version>1.1.2</version> 
</dependency> 

<!-- JSTL --> 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>jstl</artifactId> 
    <version>1.1.2</version> 
</dependency>