Web Module Mini How To

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

src (mesquite - project created module)
com
codepuccino
...

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:
files
(everything)
webapp
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:

webapp/
(all jsp files here)
media
(media files here)
WEB-INF
classes
codepuccino
....
lib
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.

R

4 comments
Comment actions Permalink

Thanks to Jonas, he pointed us to how to turn off all these exception
while we're debugging the web app. Keep in mind if you do this, you
won't be able to report bugs to JetBrains the old fashioned way, so keep
an eye on the console for important errors.

In the idea bin directory, I changed the log.xml to look like this at
the end:

]]>

And now I don't get nagged every time I press a key, and I can DEBUG my
webapps in peace... well there could be other problems now, but at least
now I can report them!!!

Robert S. Sfeir wrote:

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

src (mesquite - project created module)
com
codepuccino
...

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:
files
(everything)
webapp
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:

webapp/
(all jsp files here)
media
(media files here)
WEB-INF
classes
codepuccino
....
lib
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.

R

0
Comment actions Permalink

Appending again.

In order to debug, you need to add the webroot directory as a module.
Set its output path to itself and set the jdk. DON'T make it a
depenency of the web app module. However there is a bug here. If you
add the module, it will remove all settings for the child dependencies
in the web module. So after you add the webroot module, go back to the
web app module and re setup the dependencies. This happens whether your
module is a depenant or not to the web module.

(Gosh even typing this is confusing)

R

Robert S. Sfeir wrote:

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

src (mesquite - project created module)
com
codepuccino
...

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:
files
(everything)
webapp
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:

webapp/
(all jsp files here)
media
(media files here)
WEB-INF
classes
codepuccino
....
lib
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.

R

0
Comment actions Permalink

I have a web application which uses turbine2.3 framework.
My servlet class is org.apache.turbine.Turbine which is located
in a jar file(turbine.jar).
My web.xml file maps this servlet:
cms org.apache.turbine.Turbine But the web module from Idea does not see "cms" servlet unless I specify one class(source) that belongs to my web module(located in src directory). Just try to create a new servlet. You will have to choose a class only from your packages, those that comes from src directory. So, the only solution is to extend Turbine class and to map my class. Daniel >I use Struts, and I can configure things just fine. I'm not sure what >you mean by that. We should carry on this conversation in J2EE forum. >Maybe it's a setting you have. I've also posted a little hidden >feature which might solve your problem in the J2EE form. >R Daniel Moldovan wrote: > Thanx, Robert. I hope this is just temporary. > Another problem is that if your Servelt class is in a > jar file(like turbine is) you can not configure this directly. > The workaround is that you have to extend that class in your own source. > >]]> Daniel

0
Comment actions Permalink

Actually you need to add all the libraries you need to your web module,
this should solve that. I don't need to do anything special for the
ActionServlet in struts.

R

Daniel Moldovan wrote:

I have a web application which uses turbine2.3 framework.
My servlet class is org.apache.turbine.Turbine which is located
in a jar file(turbine.jar).
My web.xml file maps this servlet:
<servlet>
<servlet-name>cms</servlet-name>
<servlet-class>org.apache.turbine.Turbine</servlet-class>
</servlet>

But the web module from Idea does not see "cms" servlet unless I specify
one class(source) that belongs to my web module(located in src
directory). Just try to create a new servlet. You will have to choose a
class only from your packages, those that comes from src directory.

So, the only solution is to extend Turbine class and to map my class.

Daniel



>I use Struts, and I can configure things just fine. I'm not sure what
>you mean by that. We should carry on this conversation in J2EE forum.
>Maybe it's a setting you have. I've also posted a little hidden
>feature which might solve your problem in the J2EE form.

>R

Daniel Moldovan wrote:

> Thanx, Robert. I hope this is just temporary.
> Another problem is that if your Servelt class is in a
> jar file(like turbine is) you can not configure this directly.
> The workaround is that you have to extend that class in your own
source.
>
> Daniel

0

Please sign in to leave a comment.