Jimmy Clark wrote:Java-based web applications consist of much more that the code written by a programmer, e.g. Servlet container code. Moreover, these applications , i.e. servlets, need to be "properly" deployed in order to function within a web server. Placing the servlet code in a JAR file and then putting the file in the lib directory of a web application is not sufficient and will not work.
Jimmy Clark wrote:First, you should analyze the "fuctionality" that is coded in servlet form. It some cases, the "functionality" should never have been place in a "servlet" class. This practice creates uneccessary dependencies on a Java web server and potential obstacles to reusability. In most cases, "functionality" should be coded in simple POJO form and accessed from servlet classes. Here the "functionality" can live in a simple JAR file and can be easliy reused.
As an alternative, enter "web services." Common functionality then is accessed via web service from ANY application including Java servlets.
The key is to identify exactly what you what to reuse and see how you can do this efficiently.
And the last step (caveman approach) is to simply leave your servlet applications deployed in a web server and access them via URL from other applications.
Wendy Gibbons wrote:I have a common project with lots of servlets. I would love to jar this common project and use this is many other projects.
I have tried just making a normal jar, placing it in web-inf/jars and placing the servlet in the web.xml (in the normal way) but that doesn't seem to work.
Is this possible? and if so how do i do it?
The contents of the WEB-INF directory are:
- The /WEB-INF/web.xml deployment descriptor.
- The /WEB-INF/classes/ directory for servlet and utility classes. The classes in this directory must be available to the application class loader.
- The /WEB-INF/lib/*.jar area for Java ARchive files. These files contain servlets, beans, and other utility classes useful to the Web application. The Web application class loader must be able to load classes from any of these archive files.
The Web application class loader must load classes from the WEB-INF/ classes directory first, and then from library JARs in the WEB-INF/lib directory
Which exact version of Tomcat is this?
Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Wendy Gibbons wrote:
and about classpaths: I didn't set tomcat up on this pc, so anything i should be checking for?
Jimmy Clark wrote:The servlet classes need to be "deployed". Simply putting servlet classes in a JAR and sticking the JAR file in the library directory will not make them accessible or executable from other web applications, i.e. servlets.
and placing the servlet in the web.xml (in the normal way)
Don't get me started about those stupid light bulbs. |