本文介绍了Eclipse 可以将 Maven Web 项目作为“动态 Web 应用程序"导入吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

高级目标:创建一个可以在 Netbeans 和 Eclipse 中正确使用的 Maven Web 应用程序项目

High Level Goal: Create a single Maven Web Application project that can be used correctly in both Netbeans and Eclipse

将 Maven 项目转换为 Eclipse 时,使用命令时项目类型似乎没有设置为 Dynamic Web App:mvn eclipse:eclipse -Dwtpversion=2.0

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

在 Eclipse 中,如果创建一个动态 Web 应用程序,项目资源管理器中会显示更多选项,例如:JAX-WS Web Services、部署描述符等.这是一个完全不同的框架结构.

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 后,即使转换的输出显示:[INFO] 用作 WTP 服务器:Apache Tomcat v7.0,我也无法运行"它.它不想作为 Web 服务运行,而是询问我这是 Java Servlet、Applet 还是单元测试.

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.

使用动态 Web 应用程序(本机 Eclipse),运行项目时会显示以下内容:

With a Dynamic Web App (native Eclipse), this is what shows up when Running the project:

也许我对 Eclipse 的要求太高了,为了获得内置的 Web 应用功能,它不能来自 Maven?

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 应用程序,然后点击 "Convert to Maven" .拿那个 POM,修改,然后看看 netbeans 是否也会加载它.

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.

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

推荐答案

按照 jhericks 的建议,如果你使用 m2eclipse ,你不需要使用 eclipse:eclipse goal.eclipse:eclipse 目标 做的事情,m2eclipse 也可以做到.

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.

要将项目转换为动态 Web 应用程序,您可以在项目属性中配置 Project Facets 选项

To convert a project to the Dynamic Web Application , you can configure the Project Facets options in your project properties

这篇关于Eclipse 可以将 Maven Web 项目作为“动态 Web 应用程序"导入吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 15:19