Not anymore now that we have JPDA!
You can run the app server in one VM, and your IDE in another; debugging across a socket. Here's how to do it: (excerpted from Jakarta Struts Cookbook http://www.amazon.com/exec/obidos/tg/detail/-/059600771X
)
Configure the JVM running your application server to use the Java Platform Debugger Architecture (JPDA). You will need to add the following options to the java command that starts your application server:
JDK 1.3
-classic
-Xdebug
-Xnoagent
-Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
JDK 1.4
-Xdebug
-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
Then you can use any IDE or tool that supports JPDA debugging such as Eclipse, IntelliJ IDEA, and JSWAT.
The Java Platform Debugger Architecture (JPDA) has made debugging Java applications much easier—you can use any debugging tool you want independently of the application being debugged. JPDA also allows you to debug a Java application running in a separate JVM on a remote server on your network. Your local JVM, running the debugger, connects to the remote JVM across the network using the host name and a known port. In the Solution, the address specifies the port.
This approach works great when the two computers are the same—for example, your desktop machine. JPDA permits you to have two JVMs—one for your IDE or debugger, and one for the application server—that can work together. No longer do you have to run the application server and your IDE all within the same process.
If you are using Tomcat as your application server, debugging is even easier. Tomcat's startup scripts include the JPDA options that are shown in the Solution. By default Tomcat reserves port 8000 for the JPDA port.
For Win32 machines, the catalina.bat startup script configures JPDA to use shared memory, instead of TCP/IP sockets for the transport mechanism. The use of shared memory is only supported by Win32, and most IDEs do not support connecting using this transport—you're better sticking with the socket approach. If you are using a Tomcat on a Win32 machine you have two main options; you can use the Cygwin Unix emulator and execute the catalina.sh shell script, or you can modify the catalina.bat file to use sockets. Simply change the variables for the transport and address as follows:
…
rem set JPDA_TRANSPORT=dt_shmem
set JPDA_TRANSPORT=dt_socket
…
rem set JPDA_ADDRESS=jdbconn
set JPDA_ADDRESS=8000
…
Of course, you can change the JPDA_ADDRESS to any available port you like. Then execute the catalina.bat file to start Tomcat in debug mode.
Once the application server is started, you connect to the server's JVM using your debugger. You only need to specify the host name and port for the remote JVM.
-Bill Siggelkow
kjc wrote:
Debugging a server side component only works when the IDE has the ability to launch the appServer
inside the VM which is also running the IDE. You can then set breakpoints in the struts sources.
Bill Siggelkow wrote:
Scott,
Are you developing using an IDE such as Eclipse or IDEA? Most IDEs have a debugger that allows you to step through your code as it executes. There is also a standalone debugger known as JSwat.
Because you have (or can get) the Struts source, you can set breakpoints within the Struts RequestProcessor to figure out where its failing.
-Bill Siggelkow
Scott Purcell wrote:
Hello Bill,
I checked everything again, and still do not see anything obvious. What did you mean by a debugger? Do you know of one for Tomcat and checking this type of problem?
If so, please let me know.
Thanks, Scott
-----Original Message----- From: news [mailto:[EMAIL PROTECTED] Behalf Of Bill Siggelkow Sent: Thursday, November 18, 2004 12:11 PM To: [EMAIL PROTECTED] Subject: Re: Newbie With Question
Scott, this problem can happen when you are trying to forward to a non-existent location. For example, you would see this problem if the path specified in the <forward name="success" path="/submit.jsp"/> was invalid.
However, looking at your struts-config.xml I do not see any errors.
I would first check that your Struts config is not throwing any errors when it is read in (check the Tomcat console for this). Then, I would get out the debugger.
(P.S. Just a matter of style here -- by convention, package names typically use the reverse of your company's web address; so your action's fully-qualified name would be something like 'com.vertisinc.SubmitAction')
-Bill Siggelkow
Scott Purcell wrote:
Hello,
I am just getting underway with struts and found an example here: http://javaboutique.internet.com/tutorials/Struts/
I have completely followed the directions and I can get the initial form to display the data that comes from the ActionForm bean. "Hansen".
But after I hit the submit, I just get a blank page. I have double, triple checked all config settings, but cannot figure out where the problem is. The Tomcat console does not show any error, and there appears to be no error anywhere. Problem is, it just does not display the submit.jsp page back with updated results.
If anyone has ideas, please let me know. Especially if there is a way to find any type of log from Tomcat. I cannot find any type of output from the app.
Thanks, Scott
Here are my files: my webapp is called "firststrut" The classes are in package "com" The file structure is correct
/WEB-INF/classes/com package com;
import javax.servlet.http.*; import org.apache.struts.action.*;
public final class SubmitAction extends Action {
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
System.out.println("SubmitAction extends Action class ######");
SubmitForm f = (SubmitForm) form; // get the form bean
// and take the last name value
String lastName = f.getLastName(); // Translate the name to upper case //and save it in the request object request.setAttribute("lastName", lastName.toUpperCase());
// Forward control to the specified success target
return (mapping.findForward("success"));
}
}
/WEB-INF/classes/com package com;
import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.*;
public final class SubmitForm extends ActionForm {
/* Last Name */ private String lastName = "AMF"; // default value public String getLastName() { System.out.println("Getting last name"); return (this.lastName); } public void setLastName(String lastName) { this.lastName = lastName; }
/* Address */ private String address = "1313 Mockingbird Lane"; public String getAddress() { return (this.address); } public void setAddress(String address) { this.address = address; }
/* Sex */ private String sex = null; public String getSex() { return (this.sex); } public void setSex(String sex) { this.sex = sex; }
/* Married status */ private String married = null; public String getMarried() { return (this.married); } public void setMarried(String married) { this.married = married; }
/* Age */ private String age = null; public String getAge() { return (this.age); } public void setAge(String age) { this.age = age; }
}
web.xml <?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" " http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<!-- Standard Action Servlet Configuration (with debugging) --> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>application</param-name> <param-value>ApplicationResources</param-value> </init-param> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>validate</param-name> <param-value>true</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet>
<!-- Standard Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
<!-- Struts Tag Library Descriptors --> <taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib>
<taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib>
<taglib> <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib>
</web-app>
struts-config.xml <?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" " http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<!-- ========== Form Bean Definitions ================= --> <form-beans>
<form-bean name="submitForm" type="com.SubmitForm"/>
</form-beans>
<!-- ========== Action Mapping Definitions ============ --> <action-mappings>
<action path="/submit"
type="com.SubmitAction"
name="submitForm"
input="/submit.jsp"
scope="request">
<forward name="success" path="/submit.jsp"/> <forward name="failure" path="/submit.jsp"/> </action>
</action-mappings>
</struts-config>
Scott K Purcell | Developer | VERTIS | 555 Washington Ave. 4th Floor | St. Louis, MO 63101 | 314.588.0720 Ext:1320 | [EMAIL PROTECTED] | http://www.vertisinc.com <http://www.vertisinc.com/> Vertis is the premier provider of targeted advertising, media, and marketing services that drive consumers to marketers more effectively.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]