WebModule Mini-How To [but it won't work yet]

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)
jsps (mesquite-jsp-module)
common
header.jsp
...
index.jsp
security
login.jsp
...
libs (mesquite-libs-module)
struts.jar
db-ojb.jar
...
media (mesquite-media-module)
css
mesquite.css
myCool.gif
...
resources (mesquite-resources-module)
struts-config.xml
repository.xml
web.xml
...
src (mesquite-source)
com
codepuccino
...
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.

R

5 comments

Robert,
Thanks for trying.
Please see my comments inlined below

--
regards,
Alexey Kudravtsev.
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"


"Robert S. Sfeir" <robert@codepuccino.com> wrote in message news:21468314.1070948982568.JavaMail.javamailuser@localhost...

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.

You are right, plain old webapps will disappear soon

>

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)
jsps (mesquite-jsp-module)
common
header.jsp
...
index.jsp
security
login.jsp
...
libs (mesquite-libs-module)
struts.jar
db-ojb.jar
...
media (mesquite-media-module)
css
mesquite.css
myCool.gif
...
resources (mesquite-resources-module)
struts-config.xml
repository.xml
web.xml
...
src (mesquite-source)
com
codepuccino
...
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.

http://www.intellij.net/tracker/idea/viewSCR?publicId=23047

>

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.
>

In your case, I think it is necessary to have one Web module with the following setup: (I assume root folder name is mesquite)
content: mesquite
source: mesquite/src
output: mesquite/classes
web roots: mesquite
web module libraries: all jars from libs directory
web module exploded directory path: mesquite

In this setup, make process, as pointed out at http://www.intellij.org/twiki/bin/view/Main/WebModules, will place compiled Java
classes into mesquite/WEB-INF/classes, web root directories contents into mesquite (i.e. no files will be copied), libraries into
mesquite/WEB-INF/lib.

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.

The rationale behind is what if you want to keep web resources in multiple directories (e.g. mymodule/jsps, mymodule/statichtmls,
mymodule/pictures) and later combine these directories into the single deployment directory. In this case, all you need is to define
three webroots and setup them to be copied into the deployment directory (possibly under several relative paths).


>

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.
>

I'll look into it.

Hope this helps us clear things up for JetBrains.

>

R

>

Could you please send me in your project ?
So we can tweak things to handle your setup.


0

You could also take a look at my humble instructions on how to turn your existing modules on EJB or WEB modules:

http://www.intellij.net/forums/thread.jsp?forum=4&thread=52420&tstart=0&trange=15#635886

0

Alexey thanks for responding, and actally reading this thing. I was hoping it would provide some clarification on what is going on. A couple of answers to your points if I may.

1- Good to hear webapps will be gone, didn't make sense.

2- JDK: Good to see that you recognize that there is no JDK needed, but you also don't need the output path either for JSP and media files. So please make sure that the output path is not required either.

3- The way you recommend I setup the directories is either counter intuitive or we're dangerously mixing terminology here. How can my project root be the web root? When I think of a webroot, I think of a directory where my html files are stored. A directory where if I hit www.google.com/ the webroot represents the / directory. Are you saying that this is not the care? Are you saying that webroot in the IDEA world means that my whole project turns into a web project? I don't know if this is a bad thing or a good thing. How would I handle it if I had multiple web apps in the same directory (idea webroot), do I setup various web modules with the same webroot? I'll have to try this in a few minutes.

4- about the multiple webroots, this confirms that I understood #3 above. I think the terminology needs to be adjusted here, coming from a web application developer, it's very confusing.

5- I filed the bug about web.xml.

6- Project is on the way. I think that the main confusion is the webroot here. However I would still like to be able to do it my way where the webroot is in fact a separate directory where everything gets copied and compiled in. This is useful because I can see where things are falling into when I make the project. Once the make is successful, then I can have a second web module which does the same thing except that it generates a war file for deployment. Having everything in the root project is bizarre, and while I can see its usefulness, since it doesn't require extra directories or anything, it's still weird :)

Thanks
R

P.S. I'll remove most libs from my libs directory otherwise it's too big.

0

Marcus, this is indeed helpful. Once this web app thing works right we should combine both our how tos and post them to the wiki. Of course by then there could be an IDEA book somewhere that tells us how to do it.

R

0

Alexey,

I tried it with your suggestion below. here is the difference. The way you describe it below I get web.xml to work right, however as soon as I add resources directory, which contains web.xml, as a module so I can get the files in it to get copied to WEB-INF, web.xml turns red and the deployment info tab is gone.

The second thing is that when I make the web module, src files get compiled to my classes directory, a new WEB-INF directory is created with the web.xml in it, as well as the lib directory with the jar files, however there is no classes directory with the compiled source.

If I add JSPS directory has a module, and add it as a utility module, its contents don't get copied anywhere. If your explanation of webroot were to be correct before, as I'm sure it is, then I would have expected a (yuk) fully exploded jsp directory inside WEB-INF/classes directory. Nothing happened, it's like it doesn't even care about those files or know what to do with them.

So while some misteries are clearer, this is definitely not how a web module/ web app should be setup. We should never have classes, resources, database scripts etc... at the root of a web app, hence web module. There should be a directory you throw the files you need to test under.

Sending my directory to you shortly.

R

0

Please sign in to leave a comment.