Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven WebApp with Intellij - procedure

What is the procedure to make a Java EE WebApp with Maven and Intellij?

This is what I do:

  • File / New / Project
  • Project Type : Maven
  • Create From archetype : maven-archetype-webapp

But when I create a servlet IntelliJ shows a symbol on the servlet: enter image description here

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.

like image 538
fli27 Avatar asked Feb 26 '15 12:02

fli27


2 Answers

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!

like image 67
chrkv Avatar answered Sep 30 '22 19:09

chrkv


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"

enter image description here

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 ?

like image 26
fli27 Avatar answered Sep 30 '22 19:09

fli27