This is a mini-how to I started throwing together for webapp beginners. Unfortunately while putting it together, I ran into so many huge bugs that I couldn't finish it all the way and test it. Still I typed enough that perhaps it will guide some far enough to find some workarounds, and maybe give JetBrains and idea of how developers (one of them at least) work with web apps.
The issue with web modules is that the concept is so radically different from how we dealt with webapps before, that it actually takes some real adjusting, and I'm getting there. The new way of doing things, cleans everything up and doesn't look like such a mess when setting up a webapp. So I decided to re-structure my project so I can fit it better into what I would have liked it to be in the first place, and it also happens to be the better way to set things up for IDEA.
First rule: Webapps are useless now. They should be yanked from IDEA. What ever you do, DO NOT turn on web app support. Even if you do, it doesn't seem like it affects anything anymore. Forget the whole concept of web apps, it will only confuse you.
For my sanity, and yours, I've setup things from scratch so I can fit things in nicely into IDEA and what I would like things to be like.
Starting with the directory structure, I've marked the dir names and the corresponding module names.
mesquite(my app's root dir)
database (no module name nothing to deploy here, holds db scripts)
classes (just a dir to post as an output path, not sure why it's needed)
Once I setup my directories, I created a new project. It's important when you create the project and modules to be sure and set a JDK to compile with. This is kind of lame since some of the supporting modules don't compile anything, files are just copied. JetBrains should look at that.
Create a new project:
1.enter name of project and directory. In my case that's mesquite.
2.Set the output path to classes.
3.Pick a JDK.
Click next twice, since the project path is fine. Again, not sure why project path is still there, why is that any different from the first project directory. Remove the src dir since we're going to make a module for it, click next on the class path, don't add anything.
Now the project is up. Before you turn on J2EE, click on file|configure project
Create a new module for each of the above modules listed. Don't forget to set a JDK and output path for each. In the case of the mesquite-source directory, don't forget to set the proper libraries so the source code will compile. I, in this case, add them as module libraries, and all the libs happen to be in the libs directory. Again here another anomaly, the media module has to have an output path, and a JDK.
Now that you've added all of them, the last one to add is the Web Module. To add a web module you need to turn on J2EE. To do that you need to look at project properties, not configure project you won't find anything there, yet. To enable J2EE click on project properties and go to App Server Integration and check off the Generic Application Server box. That's it, don't do anything else in there (at least not at this time since nothing else works in there (up to EAP 992)). Close the project properties window.
You will now notice that in the project pane there is a new tab called J2EE. Switch to it. In the tab you will see a little blue earth icon. RIGHT Click on it and pick NEW. A new window will pop up. In that window name your web module module. In my case I named it mesquite-web-module.iml. Click OK. Window pops up with red disclaimer (JENKA get to it buddy :) ). Apparently this is all going to change (thankfully). Pick a JDK. Pick output path (classes directory). No need to change anything else. Click next.
If you don't see the correct web.xml listed in the next screen, click the ... button and pick it from under resources/web.xml. Sometimes web.xml is marked red and you can't see the deployment interface in the J2EE tab (reported as a bug). It seems the reason is that it wants to have web.xml in a content directory of the web module, but the way I've set it up it makes it impossible to do, since I would not be able to use the resources module later on. Now, In the Webroot section, add a webroot. This is an interesting since you can point your webroot anywhere you want. I just created one under my project directory. What I DON'T understand is why we have multiple webroots for one web module. Is there some kind of secret plan that we don't know of? I can't figure out an instance where this would be needed. Once you've added the webroot, click finish.
You will now see in the project pane that you have the new web module listed along with the others. Weird enough, if there is a problem with your setup, the icon for the web module won't show up right (kind of a neat fug (feature bug)), if you do it right you'll see the earth icon. If you want to add other directories to web module at this point you can do it from configure project.
Now, you can edit web.xml using the cool interface to setup your deployment process. Switch to J2EE and click on web.xml. For some reason it's 1 click... yuk. Switch to build settings. Check on Create Web Module Exploded Directory and point it to the webroot. For the supporting files add the other modules we added earlier. The resources dir should point to the WEB-INF directory root. ... Add the rest of the java modules and their appropriate directories. There seems to be no clear way of adding the mesquite-jsps module, unless I can type ../ for the path of the app so I can put those files and the media files one directory above WEB-INF. This is not quite clear.
Now add the libraries you want to copy to WEB-INF/lib, they would normally be the same libraries as those found in your project libraries. I don't know why JetBrains chose to do it this way, when we already have a libs module which contains all the libraries we want to use, and allows us to switch out libraries very easily. I think that last box is a waste of time. Maybe I'm wrong on that one.
That should be it, at this point you should be able to click the make project button and build the whole thing. If you do 2 things happen correctly:
1- WEB-INF/web.xml is created properly in the webroot
2- WEB-INF/lib is created properly and all libraries are copied over correctly.
What goes wrong:
Everything else. Classes compile to the wrong directoy (not WEB-INF/classes). Resouces are not copied over. App server doesn't start up, doesn't know what to do.
Hope this helps us clear things up for JetBrains.