masterofdisaster
masterofdisaster

Reputation: 1169

Cannot create Servlet in IntelliJ Ultimate Edition

I cannot create servlet using New -> Servlet in IntelliJ IDEA. Of course it's Ultimate edition; I've marked src/main/java as source root directory but I still cannot create it automatically. Only option left is to create it manually as I did.

Upvotes: 5

Views: 7816

Answers (6)

Peter
Peter

Reputation: 5224

Open Project Structure and select Modules. You should see a list of all your project modules. The module where you want to create a Servlet in should have a Web Facet. If not, read enabling-web-application-support.

Every source route that contains your web application Java classes should be attached as source route to your web facet. That can be done on the web facet page.

After attaching all source routes the Create New Servlet option should be available the New menu.

Upvotes: 1

Pooya Afshari
Pooya Afshari

Reputation: 39

First mark your source folder as root source folder.

Then make sure that in file > Project Structure > Facets > click Web(project name) src\main\java is under source root.

If problem not solved check your pom.xml file in maven and make sure you have Java Servlet API dependency.

Upvotes: 1

Kyaw Zayar
Kyaw Zayar

Reputation: 21

first : right click src\java > Mark directory as > source root

second : go to file > Project Structure > Facets > click Web(project name), then check src\main\java under source root.

Screnshot

Upvotes: 1

ahtasham nazeer
ahtasham nazeer

Reputation: 126

It is possible that you are missing the servlet jar, if you are using the Idea Ultimate with maven then you can add the servlet dependency to it, I use embedded tomcat which adds the servlet itself

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <version>9.0.55</version>
    </dependency>

Upvotes: 1

alpha oumar Diallo
alpha oumar Diallo

Reputation: 1

I will just write my solution here. I had the same issue turned out all i needed to do was to scroll down once i right click on java source folder. The menu create new servlet should appear at the bottom below the data source section

Upvotes: 0

Anshu Shekhar
Anshu Shekhar

Reputation: 115

I was experimenting a bit and came across a scenario, may be it help you. I created a directory main\java, which was created as a maven source directories as suggested by Intellij by default as shown in image.main\java Then i marked src as source directory and i do not get option to create new servlet under created java directory.
So in this particular case if you want to create servlet then first go to, "Mark directory as > Unmark as sources root". Now you can create servlet inside java directory as well.

Upvotes: 1

Related Questions