5

我是这种方法的新手。我的 Web 应用程序使用了 Maven、Tomcat 和 Eclipse。但我正在尝试使用原型插件创建 Maven 项目的方法。

我的目标是使用 Maven 为 Eclipse 创建一个 Web 应用程序项目,然后可以将其导入 Eclipse。我很确定有一种超级简单的方法可以做到这一点,我想知道它是什么。

我正在使用 Tomcat 6、Eclipse Helios 和 Maven 2。

我指的是这个由 3 部分组成的帖子:

http://united-coders.com/phillip-steffensen/maven-2-part-1-setting-up-a-simple-apache-maven-2-project

但是当我将项目导入 Eclipse 时,我看不到该Run As > Run on server选项。

解决此问题的最佳方法是什么?任何可以帮助我理解该方法的资源链接都会很棒!

4

3 回答 3

9

我的目标是使用 maven 为 Eclipse 创建一个 Web 应用程序项目,然后可以将其导入 Eclipse。我很确定有一种超级简单的方法可以做到这一点,我想知道它是什么。

使用 maven 原型插件生成您的项目。maven-archetype-webapp这是从命令行调用它时如何告诉它使用的方法:

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp

但是当我将项目导入 eclipse 时,我看不到 Run As > Run on server 选项。

这实际上完全取决于您用于 Eclipse/Maven 集成的内容。基本上有两种选择(它们提供 WTP 集成):

  • maven-eclipse-plugin是一个Maven 插件,可以生成 Eclipse 文件(.project等等.classpath),允许将项目作为现有项目导入 Workspace
  • m2eclipse插件,它是一个Eclipse 插件,在Eclipse中提供 Maven 集成,并允许将 Maven 项目作为现有 Maven 项目导入。

maven-eclipse-plugin 方法

If you use the maven-eclipse-plugin, you have to configure it for WTP support and here is a typical configuration:

  <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>

With this configuration, running mvn eclipse:eclipse on your maven project will generate the WTP files so that the project can be recognized as a Dynamic project (i.e. runnable on a Server). Then import it via Import... > Existing projects into Workspace.

The m2eclipse approach

If you use the m2eclipse plugin (and that would be my recommendation), make sure to install the Maven Integration for WTP from the extras. From the 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

And then just import your project via Import... > Existing Maven projects and if it's a webapp, it should get recognized as a Dynamic project.

Indigo: m2eclipse approach for Indigo is different. See Maven/Tomcat Projects In Eclipse Indigo/3.7

Important: Note that both approaches are exclusive, use one or the other. But in both cases, there is no need to add a facet manually if you use them correctly.

于 2010-08-17T16:47:37.043 回答
1

从这里下载并安装 eclipse maven 插件。使用 Eclipse 中的新项目向导创建您的项目。选择 Maven 项目并使用您讨论的原型创建项目。设置适当的源文件夹并添加用作项目属性一部分的库。这应该为您的项目做好准备。

于 2010-08-16T20:11:44.270 回答
0

Very simple,
you only have to create a new Maven project with packaging type ‘war’ and directories creation done automatically

于 2013-04-24T15:06:16.157 回答