Eclipse 可以将 Maven Web 项目作为“动态 Web 应用程序”导入吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6950103/
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
Can Eclipse import a Maven Web project as a "Dynamic Web Application"?
提问by jsidlosky
High Level Goal:Create a single Maven Web Application project that can be used correctly in both Netbeans and Eclipse
高级目标:创建一个可以在 Netbeans 和 Eclipse 中正确使用的 Maven Web 应用程序项目
When converting a Maven project to Eclipse, the project type doesn't seem to be set to Dynamic Web App when using the command: mvn eclipse:eclipse -Dwtpversion=2.0
将Maven项目转换为Eclipse时,使用命令时项目类型似乎没有设置为Dynamic Web App:mvn eclipse:eclipse -Dwtpversion=2.0
In Eclipse, if creating a Dynamic Web Application, many more options are shown in the Project Explorer, such as: JAX-WS Web Services, Deployment Descriptor, etc.It's a completely different framework structure.
在 Eclipse 中,如果创建动态 Web 应用程序,项目资源管理器中会显示更多选项,例如: JAX-WS Web 服务、部署描述符等。这是一个完全不同的框架结构。
Also, after converting to Eclipse with the above command, I can't "Run" it even though the output from the conversion says: [INFO] Using as WTP server : Apache Tomcat v7.0. Instead of wanting to run as a web service, it asks me if this is Java Servlet, Applet, or Unit test.
此外,在使用上述命令转换为 Eclipse 后,即使转换的输出显示:[INFO] 用作 WTP 服务器:Apache Tomcat v7.0,我也无法“运行”它。它不想作为 Web 服务运行,而是询问我这是 Java Servlet、Applet 还是单元测试。
With a Dynamic Web App (native Eclipse), this is what shows up when Running the project:
使用动态 Web 应用程序(本机 Eclipse),这是运行项目时显示的内容:
Maybe I am asking too much of Eclipse, and to get the built-in web app functionality, it can't come from Maven?
也许我对 Eclipse 的要求太多了,为了获得内置的 Web 应用程序功能,它不能来自 Maven?
There is one other I could try. I could create a Dynamic Web App in Eclipse, then hit "Convert to Maven" . Take that POM, modify, then see if netbeans will also load it.
还有一个我可以试试。我可以在 Eclipse 中创建一个动态 Web 应用程序,然后点击 "Convert to Maven" 。拿那个 POM,修改,然后看看 netbeans 是否也会加载它。
My 'pom.xml':
我的“pom.xml”:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.voxel</groupId>
<artifactId>servermap</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>userprofile</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-servlet-webserver</artifactId>
<version>1.9.18-m</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
采纳答案by Ken Chan
As suggested by jhericks ,if you use m2eclipse
, you don't need to use eclipse:eclipse goal
. What the eclipse:eclipse goal
does can also be done by the m2eclipse.
正如 jhericks 所建议的,如果您使用m2eclipse
,则不需要使用eclipse:eclipse goal
. 什么eclipse:eclipse goal
做,也可以由m2eclipse的完成。
To convert a project to the Dynamic Web Application , you can configure the Project Facets
options in your project properties
要将项目转换为动态 Web 应用程序,您可以Project Facets
在项目属性中配置选项
回答by jhericks
I have had better luck with the m2eclipse pluginfrom Sonatype. When I started, I made the mistake of trying to use both m2eclipse and the eclipse:eclipse goal. They don't do exactly the same thing, so if you install the plugin, stop doing mvn eclipse:eclipse. Anyway, it has worked very well for me with single web projects and very well with multi-project reactor style projects as well.
我使用Sonatype的m2eclipse 插件运气更好。当我开始时,我犯了一个错误,试图同时使用 m2eclipse 和 eclipse:eclipse 目标。他们做的事情并不完全一样,所以如果你安装了插件,停止执行 mvn eclipse:eclipse。无论如何,它对我来说非常适合单个 Web 项目,也非常适合多项目反应器风格的项目。
The only problem I've had is with trying to deploy a war file to a server configured in eclipse if that war file is built with an overlay, but that doesn't seem to be an issue for you.
我遇到的唯一问题是,如果该War文件是使用覆盖层构建的,则尝试将War文件部署到在 eclipse 中配置的服务器,但这对您来说似乎不是问题。
回答by kolobok
m2e-wtpplugin does this automatically, as stated here: Import Existing Maven in Eclipse as WTP
m2e-wtp插件会自动执行此操作,如下所述:Import Existing Maven in Eclipse as WTP
All facets, source folders etc will be correctly set after import.
导入后将正确设置所有方面、源文件夹等。