Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Eclipse import a Maven Web project as a "Dynamic Web Application"?

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

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

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.

enter image description here

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.

enter image description here

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

enter image description here

Maybe I am asking too much of Eclipse, and to get the built-in web app functionality, it can't come from 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.

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

like image 603
jsidlosky Avatar asked Aug 05 '11 00:08

jsidlosky


People also ask

Which Eclipse is used for dynamic Web project?

Eclipse Java EE Developer Tools. Eclipse Java Web Developer Tools.

How do I convert an existing dynamic Web project to Maven in eclipse?

Right-click the project and select Configure > Convert to Maven Project. Complete the Maven POM dialog. Enter a Group Id, Artifact Id, and Version or accept the defaults.


3 Answers

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.

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

enter image description here

like image 52
Ken Chan Avatar answered Sep 18 '22 21:09

Ken Chan


I have had better luck with the m2eclipse plugin from 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.

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.

like image 24
jhericks Avatar answered Sep 17 '22 21:09

jhericks


m2e-wtp plugin does this automatically, as stated here: Import Existing Maven in Eclipse as WTP

All facets, source folders etc will be correctly set after import.

https://www.eclipse.org/m2e-wtp/

like image 39
kolobok Avatar answered Sep 20 '22 21:09

kolobok