IntelliJ Community . WebModules

 
WebModules 

HOME INDEX SEARCH CHANGES GO  

Web Modules

What are Web Modules ?

Web module is a special kind of IDEA module (see IDEA project/IDEA module structure) which, in addition to usual Java module attributes (like source directories, compiler output directory, etc) knows much about Web applications:
  • Web module contains Web application deployment descriptor (aka web.xml) location and structure, including:
    • servlets, their init parameters, URL mappings
    • filters, their init parameters
    • security roles, context parameters
    • JSP files
  • Web module knows of Web application deployment directory structure, either inside WAR file or in exploded directory format. Web module is able to construct deployment directory structure during module make process. Details see below (What exactly J2EE make is doing)
  • Web module knows how to start and deploy itself to the application server (Tomcat 4.x,5,x and BEA WebLogic are supported now)

All Web module settings can be edited from J2EE View by pressing F4 on the selected Web module or servlet. Or, from the Settings/Paths/your web module.

How to create Web module ?

  1. Go to 'File/New module' menu item. (alternatively, you can choose Web modules node in the J2EE View if it shown and select 'New/ Web Module' from there)
  2. In the Web module create wizard, specify .iml file location, module root, source directories, web.xml file location.
  3. Specify web resource directories. Web resource directory contains web specific stuff like JSP files, additional deployment descriptors etc that you want to be eventually located somewhere inside deployment directory. To edit web resource dirs, go to Settings/Paths/(Your web module)/Web Module tab/Web Resource Directory pane. Note that each web resource directory contains relative path entry where corresponding files will be copied in deployment directory.
  4. Specify Web module build settings (these can be found in Settings/Paths/(your web module)/J2EE Build Settings tab).
    • Build Settings Tab/Web Module Jar File. Tells IDEA to create corresponding WAR file and allows to specify its location.
    • Build Settings Tab/Web Module Exploded Directory. Tells IDEA to create J2EE Web Application directory and allows to specify its location.
  5. Specify libraries and classes that should be in the WEB-INF/lib and WEB-INF/classes directories. (these can be found in Settings/Paths/your web module/Web module tab)
    • to specify libraries, you are:
      • adding corresponding libraries to the web module (Settings/Paths/(your web module)/Libraries tab)
      • selecting which libraries and under what relative paths (usually /WEB-INF/lib) to copy into your deployment directory (Settings/Paths/your web module/Web module tab - Modules and Libraries to deploy)
    • you can also specify classes which are come from other IDEA Java module and go into e.g. WEB-INF/classes:
      • mark corresponding Java module dependant for this Web module (Settings/Paths/your web module/Dependencies tab)
      • check that Java module and specify relative path (Settings/Paths/your web module/Web module tab - Modules and Libraries to deploy)

How to compile the Web Module and build all necessary WAR file and/or exploded directory for deployment ?

  • Press Ctrl-F9 (Make Project). This will make all project including your web module.
  • select 'Compile module XXX' in module context menu in the Project or J2EE View. This will recompile this Web module and dependant modules only
  • select 'Make module XXX' in module context menu in the Project or J2EE View. This will compile this Web module and dependant modules changed files.

QUESTIONS

Is there a way to copy modified web resources, such as JSP files, to the exploded directory without rebuilding the entire module? -- MikeKlumpenaar 27 Jan 2004

I want to work in an exploded directory, but do NOT want the files copied from the src directories. I want this so that I can edit template files and see the changes immediately without restarting tomcat. If I make the changes in the current exploded files, they will be 'lost' because they are just copies. -- TimColson 03 Feb 2004

Hey Tim, just found out how to do it... Just make sure that your J2EE Build Settings are set to create a web module exploded directory, and whenever you modify a .vm file, just recompile Ctrl+F9 and the file is copied fast, indicating that all files are up to date. No need to restart Tomcat... whohoooo! -- EmilioSuarezCisco - 06 Feb 2004

What exactly J2EE make is doing ?

  • if Build Settings/Create Web Module Jar File is checked, then WAR file will be created with the contents specified below.
  • if Build Settings/Create Web Module Exploded directory is checked, then J2EE Application directory will be created with the contents specified below.
  1. Java classes under the source directories will be compiled into respective compiler output directories and then copied to the WEB-INF/classes. Please adjust the compiler settings for copying resource files if you do not want to copy some specific files e.g. JSP files from the source folders into WEB-INF/classes.
  2. Web roots will be copied to the Web module output directory according to the web root relative paths.
  3. Containing java utility modules and libraries configured will be copied to the web module output directory corresponding to the relative paths.
  4. web.xml copied into WEB-INF directory

Sample Web module project: Hello, Web!

  1. Download and unzip the attached project into temp directory, open webref.ipr
  2. The project consists of the one and only module: SampleWebModule?. You can inspect how its configured:
Web module paths settings
Please note that
  • Module output path is set to SampleWebModule?\classes, so that Java classes will go that directory on compile.
  • Source directory created in SampleWebModule?\src.
  • Directory SampleWebModule?\webresources marked as web resource directory. Hello.jsp file is located here.
  • Servlet-api.jar is placed into lib directory and added to the module libraries, so that we can use web app-specific classes during Java code developing. You can as well configure project or global library containing servlet classes and attach it to the module.

Web module specific settings

  • in the Web module tab we can see that deployment descriptor location set up to SampleWebModule?\web.xml

Web module build settings

In the Web module build settings tab we can see that:

  • deployment directory will be created in SampleWebModule?\deploy
  • WAR file will be created in SampleWebModule?\SampleWebModule.war

  1. Make the project
  2. Setup web module run configuration. There is run configuration 'SampleWeb' which is setup to run Tomcat 5.0 server. You will need to adjust tomcat installation location paths to run that configuration successfully.
  3. Run web module. Tomcat server should start. Open browser and point it to the e.g. http://localhost:8080/examples (if your tomcat was setup to use localhost and port 8080 and context '/examples'). HelloServlet? output will appear showing hyperlink to 'hello.jsp'.

Web module run

Please use build 1116 and higher to load this module

-- AlexeyKudravtsev - 08 Dec 2003

Attachment: sort Action: Size: Date: Who: Comment:
webref.zip action 100577 22 Jan 2004 - 12:43 AlexeyKudravtsev  

e d i t a t t a c h r e f - b y d i f f s m o r e
Have ideas, requests, problems regarding this site? Send feedback.
Copyright © 2000-2003 by the contributing authors. All materials at intellij.org are the property of the contributing authors.