Click to See Complete Forum and Search --> : war deployment
daina
03-02-2006, 05:27 AM
Hi
I have a war file called test.war which contains all my jsp page & web.xml.I have made a jar file called test.jar which contains all my classes. Then I copied these file to tomcat webapps folder.when I start the tomcat. test.war file got unzipped to folder test.Then I put test.jar inside the web-inf of test folder.I changed the web.xml to the following to know my class file
are inside test.jar
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>DBHandler</servlet-name>
<servlet-class>test.jar/Sample.DBHandler</servlet-class> <--- to know where is class
</servlet>
<servlet-mapping>
<servlet-name>DBHandler</servlet-name>
<url-pattern>/DBHandler</url-pattern>
</servlet-mapping>
</web-app>
But when I run the program It is showing error as package name not found. Can anyone tell me what to do.I know this is not the right way, to put my jar inside the web-inf.But I have to put my class files in JAR file only.& and my jsp page & web.xml inside war file.Can anyone tell me what to do.I know I have to modify the web.xml to say all the class r there inside the test.jar.How to do that.
Khalid Ali
03-02-2006, 10:34 AM
u don't need to do this
<servlet-class>test.jar/Sample.DBHandler</servlet-class>
instead do this
<servlet-class>Sample.DBHandler</servlet-class>
and make sure that u include the jar file inside ur war file so that u do not have to copy it afterwards.
WEB-INF/*.jar
/web.xml
and then servlet mapping if any required inside of the web.xml
daina
03-02-2006, 11:37 PM
Hi
Ihave done that. But it show the same error.package Sample not found.The test folder has the following structure.
TEST
+META-INF
+WEB-INF
+ web.xml
+ test.jar
+register.jsp
+process.jsp
The web.xml has the following
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>DBHandler</servlet-name>
<servlet-class>Sample.DBHandler</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DBHandler</servlet-name>
<url-pattern>/DBHandler</url-pattern>
</servlet-mapping>
</web-app>
Can u tell me what to do.
Khalid Ali
03-02-2006, 11:47 PM
yes except one t hing that I forgot to mention that put the jar file in the lib directory under WEB-INF folder so that it looks like this
WEB-INF/
/web.xml
/lib
/lib/*.jar
my bad wasn't thinking straight..:-)
daina
03-03-2006, 12:11 AM
Hi
Thanks for your replay.I did that. I put test.jar in lib folder of web-inf.
WEB-INF/
/web.xml
/lib/test.jar
But same error is comming as
D:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\test\process_jsp.java:43: package Sample does not exist
Sample.FormBean formHandler = null;
^
An error occurred at line: 4 in the jsp file: /process.jsp
Generated servlet error:
D:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\test\process_jsp.java:45: package Sample does not exist
formHandler = (Sample.FormBean) pageContext.getAttribute("formHandler", PageContext.REQUEST_SCOPE);
^
Can u tell me what to do.I have put all my classes in test.jar.The jsp is in test.war.When tomcat started. the test.war is unzipping to the test folder .When I looked it has the test.jar in lib dir of web-inf.Do I have to say anything in web.xml to say that classes are there in lib.
Khalid Ali
03-03-2006, 12:24 AM
did u do an import of file in question in the jsp page?
you want to do that too in addition to the directory structure.
daina
03-03-2006, 12:46 AM
Hi
I did that. The first jsp page is comming .That page will call process.jsp.In that we call the class.The code of process.jsp page is
<%@ page import="java.util.*" %>
<%@ page import="Sample.FormBean" %>
<jsp:useBean id="formHandler" class="Sample.FormBean" scope="request">
<jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>
<% if (formHandler.validate()) {
%>
<jsp:forward page="DBHandler" />
<%
}else {
%>
<jsp:forward page="retry.jsp"/>
<%
}
%>
It is showing the same errror.
D:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\test\process_jsp.java:8: package Sample does not exist
import Sample.FormBean;
^
D:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\test\process_jsp.java:45: package Sample does not exist
Sample.FormBean formHandler = null;
^
An error occurred at line: 5 in the jsp file: /process.jsp
Generated servlet error:
D:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\test\process_jsp.java:47: package Sample does not exist
formHandler = (Sample.FormBean) pageContext.getAttribute("formHandler", PageContext.REQUEST_SCOPE);
^
An error occurred at line: 5 in the jsp file: /process.jsp
Generated servlet error:
D:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\test\process_jsp.java:50: package Sample does not exist
formHandler = (Sample.FormBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "Sample.FormBean");
^
4 errors
Can u tell me what to do.
Khalid Ali
03-03-2006, 01:32 AM
zip up all of ur project and upload it here or email it to me..I will take a look
daina
03-03-2006, 02:00 AM
Hi Khalid,
Thanks a lot.It worked.When I unzipped the jar file.It comming as
WEB-INF/classes/Sample/DBHandler.class. So I made jar which starts from Package name Sample.Then I put it into lib. import the class name in jsp.then it is working.Thanks for your very fast responses and help once again.
Thanks & Regards,
Daina
Khalid Ali
03-03-2006, 08:26 AM
glad to be of a help....:-)
I knew what I had told u to do was correct and u shouldnt have any problem with that...did not know ur jar file had a diff directory structure then what u are trying...heheheh
daina
03-04-2006, 12:02 AM
Hi Khalid
Sorry.My mistake.I didn't look the directory structure.When I unzipped it.I saw that.Thanks for your help again...............