Reputation: 319
What is the procedure to make a Java EE WebApp with Maven and Intellij?
This is what I do:
But when I create a servlet IntelliJ shows a symbol on the servlet:
This symbol is "Java class located out of the source root. Refer to the section Configuring Content Roots for details"
If I launch the project I get an error.
If I mark the "resources" directory as "Sources Root", the project works.
But if I reload Maven (right click / maven / reimport) the resources directory lost the "Source Root" structure.
I think something is wrong in my procedure.
Upvotes: 13
Views: 13277
Reputation: 498
I'd also encountered the same issue and found a solution by replacing the dependency:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
by following dependency
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
after adding this and making the java the source root directory as mentioned in above answer, the intellij idea provided the option for creating filters along with web services. I followed the steps from the link : http://www.tugay.biz/2013/10/hello-world-web-application-with-maven.html
Upvotes: 0
Reputation: 319
Thank you to Chrkv !
1). Create a new folder under main called java. Then right-click it and select Mark Directory As -> Sources Root
2). In Project Structure / Modules / Web enable the checkbox for makes java "Sources Root"
Now i can use right click on java / New / Servlet.
What is the "resources" directory ? (if i cant create servlet here)
Is this the right precedure ?
Upvotes: 3
Reputation: 648
Create a new folder under main called java. Then right-click it and select Mark Directory As -> Sources Root. Use this directory for all your java code and everything should work!
Upvotes: 21