Davoud
Davoud

Reputation: 2933

How can I create Servlet project with maven in Intellij Idea?

I have created a maven project in Intellij Idea. I also added jetty's maven dependency to pom file. What should I do then to create servlet project? Should I create webapp\WEB-INF\web.xml folder in main\java manually? or there is some maven plugins which I must add to Pom.xml file and after clicking install in Lifecycle, related folders and files will be created automatically?

Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.c.helloWorldMavenServlet</groupId>
<artifactId>helloWorldMavenServlet</artifactId>
<version>1.0-SNAPSHOT</version>


<dependencies>

    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>8.1.16.v20140903</version>
        <scope>test</scope>
    </dependency>
</dependencies>



</project>

Upvotes: 1

Views: 2334

Answers (1)

PawelW
PawelW

Reputation: 17

I recommend to use maven archetype to create project: org.apache.maven.archetypes:maven-archetype-webapp Then you should create directory java in src/main,then right click-> Mark Directory As -> Sources Root. By default, you have web.xml in version 2.3 so that's mean you cannot user CDI for example. If you want to change it go to File->Project Structure->Facets(or Modules) and then delete Web Descriptor from Deployment Descriptors and then add new web.xml(+) and choose version 3.1.

I hope it should work. At this moment I don't know any other way to achieve that

Upvotes: 1

Related Questions