Ok here we go again. Took me a good 4 hours to figure this out. This alone should scream to JetBrains BAD BAD BAD UI. But the UI keeps changing, so we'll hang in there.
The other MAJOR caveat. Some of the settings won't be saved on the first try. For example child module settings always get set on the SECOND try, never on the first, so you have to do the steps twice right now, but they will eventually be saved.
Third caveat is that web.xml has to be at the root of your project directory, seems IDEA refuses to save a different directory right now.
So here we go.
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)
src (mesquite - project created module)
classes (just a dir to post as an output path, not sure why it's needed)
webapp (this is the root of your web application where you're going to deploy the files into, this is where Tomcat will load files to debug things, this is the web root)
web.xml(because it will only look for it here)
You don't have to do all this, I do that because I use struts. If you have a simple web setup, at the very least you need the webapp directory, and put the rest of the files in another dir. The reason for that is that idea will complain about recursive copying if you don't. So in a simple setup do this:
web.xml (because it will only look for it here)
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.
Now the project is up. Turn on J2EE, click on ide settings, bottom of the panel J2EE, click and check off the box. Nothing else to do.
Create a new module for each of the above modules listed. Don't forget to set a JDK and output path for each, I hope this changes soon.
The output path needs to be for:
mesquite/src (the project created module) the output path is classes
mesquite/jsp (the mesquite-jsp-module) the output path is mesquite/jsp (yes same dir as the dir containing the jsp files)
mesquite/resources the output path is mesquite/resources
mesquite/lib the output path is mesquite/lib
mesquite/media the output path is mesquite/media
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.
Now add the web module. In the ide settings when you add a module, click on the j2ee button, choose web module at the bottom of the list. For the output path of the web module select mesquite/classes. Don't add a content entry, leave it empty. Under libraries add the global/project or module libraries you need to run your web app. set your jdk here too. under dependancies tab, check off all the modules except mesquite-lib the libraries module. ignore the order tab.
The webmodule tab is where most of the meat is:
- In general settings: you'll see web.xml pointed to the web.xml at the root of your project. Don't bother changing it, it won't remember the settings. It did it for me once, but I can't get it to do it again, so for now, we leave web.xml at the root of the project. Don't bother entering comments it won't save them. If you use struts it will also look like nothing is working right, since it doesn't display the name... everything is fine.
- Web Roots: click add, and add a new webroot by pointing the directory to the webapp directory with replative path of /. You will have to do this one twice, it doesn't seem to save the first time.
- Child modules: Since you checked off all the directories for dependancies, you'll see the modules listed there. check the box for all of them, and idea will intelligently figure out most of them. The ones that needs to be changed are jsps, media and resouces. The path for jsps and media is ., and the one for resouces is WEB-INF. The reason why it's . is because the webroot points at webapp and webapp is /, hence . is /. If you set your webroot to the root of your project, then . becomes /webapp, and WEB-INF would become /webapp/WEB-INF. It's all relative.
- J2EE Build Settings: I've tried to make a way, it doesn't always work. I use the exploded directory. Point that directory to the webapp directory of your project, click ok and close.
Now you will have to save the module, click ok, and go back in the web module and double check everything over because some of the settings need to be done twice, sometimes 3.
Once this is setup, click the make button. If you set everything right, it should compile everything, and copy them with the strutcture below in the webapp directory:
(all jsp files here)
(media files here)
all jar files should be here.
(all resouce files here)
If you're getting an error on make which says that you might have a recursion problem, check all your directories and make sure the webroot settings were saved right.
Now you can add a new run process. Just add a webapp like you used to. you will notice the web module is there. You still need to setup a context path for the application, so be sure you've edited server.xml in apache properly.
you should be set to run your webapp now. It does throw a lot of exceptions which makes it hard to debug, but you can run the app OK.
Hope this helps.