0

I am a student, I write final work at university, with Java EE I work half a year.

Below is what am looking for:

I need to create a web application (servlets/jsp) as a JAR file which can be added in another web application in WEB-INF/lib folder. And it should be made available by making an entry in web.xml file.

Can this be done?

Sergey
  • 879
  • 1
  • 11
  • 16
  • 1
    If you use Servlet 3.0 you can please check the following question http://stackoverflow.com/questions/5013917/can-i-serve-jsps-from-inside-a-jar-in-lib-or-is-there-a-workaround – seenukarthi May 09 '13 at 08:02
  • @Karthikeyan, I use WebSphere Application Server 7 with Servlet 2.5. This post don't solve my problem. – Sergey May 10 '13 at 08:47

1 Answers1

0

Of course you can do that:

1) Create Servlet classes / JSP files. Package them all in a jar file. Don't include web.xml or any other files.

2) Import the jar in your web application classpath.

3) Configure Servlet classes and JSP files in your web.xml as below:

For JSP:

<servlet>
    <servlet-name>MyJSPFile</servlet-name>
    <jsp-file>/path/to/jsp/MyJSP.jsp</jsp-file>
</servlet>

<servlet-mapping>
    <servlet-name>MyJSPFile</servlet-name>
    <url-pattern>/MyJSP.jsp</url-pattern>
</servlet-mapping>

For Servlet:

<servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>my.servlet.classpath.MyServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/MyServlet.do</url-pattern>
</servlet-mapping>
Sergey
  • 879
  • 1
  • 11
  • 16
Ravi Trivedi
  • 2,340
  • 2
  • 14
  • 20