Java 在 Maven 中包含 JSTL 依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2276083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Include JSTL dependency with Maven
提问by flybywire
I am using maven2, how do I add a dependency to JSTL (The JSP Standard Tag Library) ?
我正在使用 maven2,如何向 JSTL(JSP 标准标记库)添加依赖项?
采纳答案by Shayan
You need to add it to your pom.xml file.
您需要将其添加到 pom.xml 文件中。
In the dependencies node you need to add a reference to JSTL. You will probably need to set its scope to compile. So it would look something like this
在依赖项节点中,您需要添加对 JSTL 的引用。您可能需要设置其编译范围。所以它看起来像这样
<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 分发存储库的正确引用
回答by Jerry Tian
The dependencies mentioned above is not enough for me(using Tomcat 5.x as servlet container, which doesn't provide JSTL implementation itself). It just imports the according JSTL interface package into project, and will cause a runtime error in Tomcat.
上面提到的依赖对我来说还不够(使用 Tomcat 5.x 作为 servlet 容器,它本身不提供 JSTL 实现)。它只是将相应的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>
回答by Mamut
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
回答by vanduc1102
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库后:
回答by JavaSheriff
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: -->
回答by Koray Tugay
<!-- 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>
回答by N.Neupane
It seems in the last few weeks or so the Maven JSTL dependency has vanished from at least the central repository. This has caused a number of issues around the web.
似乎在过去几周左右,Maven JSTL 依赖项至少从中央存储库中消失了。这在网络上引起了许多问题。
Oracle has released the separate API and implementation dependencies which is really how they should be broken down. Now, instead of having one javax.servlet.jstl dependency you will use the following:
Oracle 已经发布了单独的 API 和实现依赖项,这才是它们真正的分解方式。现在,您将使用以下内容,而不是拥有一个 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.
这有效。