2010-02-16 175 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>