Cannot packages nor servlets in a Maven web project...

Answered

I'm testing IntelliJ with a Maven Project, it creates the Project fine, the problem is that I don't see the option to add a Servlet, and i don't see an option to add a package eather. just JSP and JSF pages, this is the sub-menu I get, how can I add a servlet and a package?

You can see the submenu I get in the attached picture.

I found the way in the View->Tools->Web menu, in that view i can right click and add a Servlet, but it doens't do anything, it doesn't create the class nor the servlet declartation in the web.xml file, it simple does nothing.



Attachment(s):
intellij_maven_no_add_servlet_option.png
20 comments
Comment actions Permalink

src/main/java is not configured as a source folder.

Did you actually import this project from Maven? Please share your pom.xml, what packaging method does it define?

0
Comment actions Permalink

Hi, I created the project directly from IntelliJ (a Maven project using a webapp archeotype), I added the java folder manually, here is the 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.aam</groupId>
  <artifactId>webappx</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>webappx Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>webappx</finalName>
  </build>
</project>
0
Comment actions Permalink

After importing the Maven project java directory will be configured as Sources automatically:

http://i.imgur.com/Ictz7wT.png

Please make sure you are using IDEA Ultimate as these features are not available in Community.

If it still doesn't work for you, please submit a ticket to support at https://intellij-support.jetbrains.com/home/ , attach your project and idea.log (https://intellij-support.jetbrains.com/entries/23352446).

0
Comment actions Permalink

Thank you.

I marked the directory as Source Directory and I was able to create packages and classes.

0
Comment actions Permalink

I have a similar problem, but in my case, the java folder is market as the source and I have already added the servlet dependency in the pom.xml file but I am still not able to see the option to create a servlet java class.

 

0
Comment actions Permalink

Do you have IntelliJ IDEA Ultimate? Did you disable any plug-ins?

0
Comment actions Permalink

I am using IntelliJ IDEA Ultimate and I didn't disable any plugin

0
Comment actions Permalink

I checked if is there any file template for servlet and there is no template.

0
Comment actions Permalink

Please provide the screenshot showing the New menu for the source root where Servlet option is missing. Also upload the logs (Help | Compress Logs and Show in ...) at https://uploads.services.jetbrains.com/ and specify the file name here.

0
Comment actions Permalink

I have uploaded the filename:

 tvictoriano-logs.zip
0
Comment actions Permalink

I will try to uninstall it and install one of the 2018 versions.

0
Comment actions Permalink

I managed to get it solved. I had to first create a simple maven project without any archetype defined and after I had to add the Java EE framework on the created project.

0
Comment actions Permalink

Had the same problem but solved it by removing 

<scope>provided<scope> from the dependency!!


new depedency:

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
0
Comment actions Permalink

I came across a scenario, it may be useful for someone.

https://stackoverflow.com/a/59481579/6456330

0
Comment actions Permalink

Tried above:

-Marked Java as source root

-Make sure the servlet package is there.

-Using Ultimate Intellij

-rebuilt maven and reimported

-removed the <scope> code

-web.xml is in my structure

-deleted projects and recreated it multiple times

Any ideas?

-------------------------

reedited: After two-hour investigation,

I realized that the UI has been changed.

Instead of being called "Servlet" at the last third line, it is called "Create New Servlet" at the last fifth line.

 

1
Comment actions Permalink

Please provide the sample project and the screenshot of the issue. You can upload the files at https://uploads.services.jetbrains.com/.

0

Please sign in to leave a comment.