java 使用 pom.xml 和 web.xml 的 web 项目之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10227244/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:07:27  来源:igfitidea点击:

Difference between web projects with pom.xml and web.xml

javajakarta-ee

提问by TechSpellBound

What is the difference between Java projects having pom.xml and web.xml? Can projects have both these configurations at the same time?

具有 pom.xml 和 web.xml 的 Java 项目有什么区别?项目可以同时拥有这两种配置吗?

回答by Xavi López

They're completely compatible. As a matter of fact, they perform completely unrelated tasks.

它们完全兼容。事实上,它们执行完全不相关的任务。

pom.xmlis the configuration file for Maven projects. One of its goals is to provide assistance in the compilation and building of a project when using Maven. You can think of it as an ant build.xmlfile or a makefileMake file if you're not familiar to Maven (actually, it can provide a lot more functionality)

pom.xmlMaven 项目配置文件。它的目标之一是在使用 Maven 时为项目的编译和构建提供帮助。如果你对 Maven 不熟悉,你可以把它想象成一个 antbuild.xml文件或者一个makefileMake 文件(实际上它可以提供更多的功能)

web.xmlis the Java EE web application deployment descriptor, where you specify for instance servlets, servlet mappings and other aspects of a webapp.

web.xml是 Java EE Web 应用程序部署描述符,您可以在其中指定 servlet、servlet 映射和 Web 应用程序的其他方面。

回答by Perception

The two files have nothing to do with each other.

这两个文件彼此无关。

  • pom.xml- Maven configuration file. Controls the build process for the project
  • web.xml- Web application configuration file. Controls the deployment and configuration of the web application
  • pom.xml- Maven 配置文件。控制项目的构建过程
  • web.xml- Web 应用程序配置文件。控制 Web 应用程序的部署和配置

The POM file really shouldn't be deployed with the application, its just for the build process.

POM 文件真的不应该与应用程序一起部署,它只是用于构建过程。

回答by Joachim Sauer

web.xmlis an indicator that the project is running in some kind of servlet container (possibly even a full-fledged Java EE container).

web.xml是项目在某种 servlet 容器(甚至可能是成熟的 Java EE 容器)中运行的指标。

pom.xmlis an indicator that the project is built using the Maven build system.

pom.xml是使用Maven 构建系统构建项目的指示符。

Those two things are entirely orthogonal, so any given project can have none, one or both of them.

这两件事是完全正交的,因此任何给定的项目都可以没有,其中之一或两者都有。

回答by Davos555

The Pom defines any dependancy libraries, it is part of Maven. This tells maven what jar files to download and store in the lib folder of your site.

Pom 定义了任何依赖库,它是 Maven 的一部分。这会告诉 Maven 下载哪些 jar 文件并将其存储在您站点的 lib 文件夹中。

Web xml is how your web project is configured.

Web xml 是您的 Web 项目的配置方式。

They can both coexist as they do different things.

它们可以共存,因为它们做不同的事情。

回答by Euclides Mulémbwè

POM stands for "Project Object Model". It is an XML representation of a Maven project held in a file named pom.xml. http://maven.apache.org/pom.html

POM 代表“项目对象模型”。它是保存在名为 pom.xml 的文件中的 Maven 项目的 XML 表示。http://maven.apache.org/pom.html

yes you can have both configurations at the same time.

是的,您可以同时拥有两种配置。

回答by ke20

The pom.xml is for configure your project with Maven.

pom.xml 用于使用 Maven 配置您的项目。

The web.xml is use in all Java EE project under Tomcat for example.

例如,Tomcat 下的所有 Java EE 项目都使用 web.xml。

You can use both, Maven is for compile and deploy your project, Tomcat is your server.

两者都可以使用,Maven 用于编译和部署您的项目,Tomcat 是您的服务器。