我对这种方法很陌生。我在我的 Web 应用程序中使用了 Maven、Tomcat 和 Eclipse。但我正在尝试使用 archetype 插件创建 Maven 项目的方法。
我的目标是使用 Maven 创建一个适用于 Eclipse 的 Web 应用程序项目,然后可以将其导入到 Eclipse 中。我很确定有一种 super 简单的方法可以做到这一点,我想知道它是什么。
我正在使用 Tomcat 6、Eclipse Helios 和 Maven 2。
我指的是这篇由三部分组成的帖子:
但是当我将项目导入 Eclipse 时,我看不到 Run As > Run on server
选项。
解决这个问题的最佳方法是什么?任何可以帮助我理解该方法的资源链接都很棒!
最佳答案
My goal is to create a Web Application Project for eclipse using maven that can then be imported into Eclipse. I'm pretty sure there is a super-easy way to do this and I want to know what it is.
使用 maven archetype 插件生成您的项目。以下是如何告诉它在从命令行调用时使用 maven-archetype-webapp
:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp
But when I imported the project into eclipse, I couldn't see the Run As > Run on server option.
这实际上完全取决于您用于 Eclipse/Maven 集成的内容。基本上有两个选项(它们都提供 WTP 集成):
maven-eclipse-plugin
这是一个 Maven 插件,可以生成 Eclipse 文件(.project
和.classpath
等),允许将项目导入为 将现有项目放入工作区。- m2eclipse插件,它是一个 Eclipse 插件,在 Eclipse 内提供 Maven 集成,并允许将 Maven 项目作为现有 Maven 项目导入。
maven-eclipse-plugin 方法
如果您使用maven-eclipse-plugin
,则必须将其配置为 WTP support这是一个典型的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<projectNameTemplate>[artifactId]-[version]</projectNameTemplate>
<wtpmanifest>true</wtpmanifest>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>2.0</wtpversion>
<manifest>${basedir}/src/main/resources/META-INF/MANIFEST.MF</manifest>
</configuration>
</plugin>
使用此配置,在您的 maven 项目上运行 mvn eclipse:eclipse
将生成 WTP 文件,以便该项目可以被识别为动态项目(即可在服务器上运行)。然后通过导入...>将现有项目导入工作区将其导入。
m2eclipse 方法
如果您使用 m2eclipse 插件(这是我的建议),请确保从附加组件中安装Maven Integration for WTP。来自 install instructions :
Installing m2eclipse Extras
To install optional m2eclipse components, you will need to use the m2eclipse Extras update site. This update site contains the following m2eclipse components:
- Maven SCM Integration
- Maven SCM handler for Team/CVS
- Maven SCM handler for Subclipse
- Maven issue tracking configurator for Mylyn 3.x
- Maven Integration for WTP
- M2Eclipse Extensions Development Support
m2eclipse Extras Update Site: http://m2eclipse.sonatype.org/sites/m2e-extras
然后只需通过导入...>现有 Maven 项目导入您的项目,如果它是一个 Web 应用程序,它应该被识别为动态项目。
Indigo: Indigo 的 m2eclipse 方法有所不同。请参阅Maven/Tomcat Projects In Eclipse Indigo/3.7
重要提示:请注意,这两种方法都是互斥的,使用其中一种或另一种。但在这两种情况下,如果正确使用它们,则无需手动添加构面。
关于eclipse - 使用 Maven 为 Eclipse 生成 Web 应用程序项目。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3496913/