使用原型的新Maven项目:为什么要在POM中复制javaee-endorsed-api.jar? [英] New Maven project using archetypes: why is javaee-endorsed-api.jar being copied in POM?

查看:74
本文介绍了使用原型的新Maven项目:为什么要在POM中复制javaee-endorsed-api.jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个Maven原型( webapp-javaee6 )来创建一个新的Java EE 6项目,但是不明白为什么某些东西放在 build POM的元素。具体来说,我不明白为什么将 javaee-endorsed-api.jar 复制到endorsed目录。根据问题,这是编译时需要的,但是当我删除 build 下的相关插件元素时,我的项目编译得很好。

I've used a Maven archetype (webapp-javaee6) to create a new Java EE 6 project but don't understand why certain things are put inside the build element of the POM. To be specific I don't understand why the javaee-endorsed-api.jar is copied over to the endorsed directory. According to the answer to this question, this is needed for compilation but my project compiles fine when I remove the related plugin element under build.

由于 javax:javaee-web-api 已作为POM中的依赖项提供,这不是用于编译?

Since javax:javaee-web-api is already provided as a dependency in the POM, can this not be used for compiling?

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>


推荐答案

它应该编译,因为还有依赖关系这件神器:

It should compile, because there is also a dependency to this artifact:

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Maven手册页描述 提供 ,如下所示:

Maven manual page describes provided as follows:


这很像compile,但表示您希望JDK或容器在运行时提供依赖项。例如,在为Java Enterprise Edition构建Web应用程序时,您可以将Servlet API和相关Java EE API的依赖关系设置为提供的范围,因为Web容器提供了这些类。此范围仅在编译和测试类路径中可用,并且不可传递。

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

所以在我看来,复制此依赖项没有影响在编译。

So in my opinion copying this dependency has no impact on compiling.

然而,archetype的作者出于某种原因希望将Java EE 6 API包复制到背书目录。如果您决定启动Jetty服务器并在测试阶段(例如使用JUnit)中进行一些测试,这可能会有所帮助。

However archetype's author wanted for some reason to copy Java EE 6 API package to endorsed directory. This might be helpful if you decide to start Jetty server and do some testing in "Test Phase" (for example with JUnit).

如果你没有使用它 - 只需删除它。

If you're not using it - just remove it.

这篇关于使用原型的新Maven项目:为什么要在POM中复制javaee-endorsed-api.jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆