简体   繁体   English

在 Maven 中包含 JSTL 依赖项

[英]Include JSTL dependency with Maven

我正在使用 maven2,如何向 JSTL(JSP 标准标记库)添加依赖项?

The dependencies mentioned above is not enough for me(using Tomcat 5.x as servlet container, which doesn't provide JSTL implementation itself).上面提到的依赖对我来说还不够(使用 Tomcat 5.x 作为 servlet 容器,它本身不提供 JSTL 实现)。 It just imports the according JSTL interface package into project, and will cause a runtime error in Tomcat.它只是将相应的JSTL接口包导入到项目中,会导致Tomcat运行时错误。

Here is the dependency part used in my project, hopefully can help others out.这是我项目中使用的依赖部分,希望可以帮助其他人。 The hardest part is the naming of the Apache's JSTL implementation in repository.最困难的部分是在存储库中命名 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>

You need to add it to your pom.xml file.您需要将其添加到 pom.xml 文件中。

In the dependencies node you need to add a reference to JSTL.在依赖项节点中,您需要添加对 JSTL 的引用。 You will probably need to set its scope to compile.您可能需要设置其编译范围。 So it would look something like this所以它看起来像这样

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

This is assuming you have the proper references to the maven distribution repository in your pom.xml or settings.xml这是假设您在 pom.xml 或 settings.xml 中有对 maven 分发存储库的正确引用

<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

http://mvnrepository.com/artifact/jstl/jstl/1.2 http://mvnrepository.com/artifact/jstl/jstl/1.2

I had the same problem.我有同样的问题。 I solved it by adding Apache Tomcat libraries to the Java build path.我通过将 Apache Tomcat 库添加到 Java 构建路径来解决它。

See my screenshots, I am using Maven:看我的截图,我正在使用 Maven:

Before adding Tomcat libraries:添加Tomcat库之前:

描述

After adding Tomcat libraries:添加Tomcat库后:

描述

From: 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: -->
<!-- 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>

It seems in the last few weeks or so the Maven JSTL dependency has vanished from at least the central repository.似乎在过去几周左右,Maven JSTL 依赖项至少从中央存储库中消失了。 This has caused a number of issues around the web.这在网络上引起了许多问题。

Oracle has released the separate API and implementation dependencies which is really how they should be broken down. Oracle 已经发布了单独的 API 和实现依赖项,这才是它们真正的分解方式。 Now, instead of having one javax.servlet.jstl dependency you will use the following:现在,您将使用以下内容,而不是拥有一个 javax.servlet.jstl 依赖项:

<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>jstl-api</artifactId>
    <version>1.2</version>
</dependency>

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>jstl-impl</artifactId>
    <version>1.2</version>
</dependency>

And this works.这有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM