Eclipse的远程调试不会在我的断点处停止

时间:2018-10-01 23:03:01

标签: war remote-debugging

我通常从不发布有关stackoverflow的问题,因为我总是能找到答案,但是在这种情况下,我花了整整一周的时间试图让eclipse调试我的远程WAR文件,但这是不可能的。我的战争项目只是一个Hello Word,只有一个文件BackTest.java

package alxFinancial.dispatcher;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import javax.servlet.*;
import java.io.*;

/**
 * Servlet implementation class BackTest
 */
@WebServlet("/BackTest")
public class BackTest extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public BackTest() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse 
    response) throws ServletException,IOException 
    {
       response.setContentType("text/html");
       PrintWriter pw = response.getWriter();
       pw.println("<html>");
       pw.println("<head><title>Hello World</title></title>");
       pw.println("<body>");
       pw.println("<h1>Hello World</h1>");
       pw.println("</body></html>");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse 
    response) throws ServletException,IOException
    {
       doGet(request, response);
    }

}

我创建了一个ant build.xml文件来编译war文件。我确保在调试器选项中包含源代码,变量和行以及debug =“ true”。

<project name="orderManager" default="war_dispatcher" basedir=".">
<!-- set global properties for this build -->
<property name="build" location="build"/>
<property name="lib" location="build/lib"/>
<property name="jar_path" 
location="/home/alex/Documents/Projects/Finance/Framework/Java/jars"/>
<property name="lib_alxFinancial" location="build/lib/alxFinancial"/>
<property name="lib_dispatcher" location="build/lib/dispatcher"/>
<property name="target" location="build/target"/>
<property name="webxml" location="ressources/dispatcher/webContent/WEB-
INF/web.xml"/>
<property name="web_directory" location="ressources/dispatcher/webContent"/>
<property name="src" location="src"/>
<property name="src_dispatcher" location="src/dispatcher"/>
<property name="src_alxFinancial" location="src/alxFinancial"/>
<property name="main-class" value="orderManager.Test" />
<property name="client-main-class" value="orderManager.Client" />
<property name="server-main-class" value="orderManager.OrderServer" />
<property name="quoteUpdate-main-class" value="quoteUpdate.Test" />
<property name="strategyManager-main-class" 
value="strategyManager.StrategyManagerServer" />

<property name="ressources" value="ressources" />


<path id="dispatcher.classpath">
 <fileset dir="/home/alex/Documents/Projects/Finance/Framework/Java/jars">
    <include name="**/*.jar"/>
 </fileset>
</path>

<target name="init">
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
    <mkdir dir="${lib}"/>
    <mkdir dir="${lib_alxFinancial}"/>
    <mkdir dir="${lib_dispatcher}"/>
    <mkdir dir="${target}"/>
</target>


<target name="build_dispatcher" depends="init" description="Compile 
dispatcher source">

<javac srcdir="${src_dispatcher}" destdir="${lib_dispatcher}" debug="true" 
    includeantruntime="false" debuglevel="lines,vars,source" source="1.8" 
    target="1.8">
    <classpath refid="dispatcher.classpath"/>
</javac>

</target>

<target name="war_dispatcher" depends="build_dispatcher">
  <war warfile="${target}/Dispatcher.war" webxml="${webxml}">
  <classes dir="${lib_dispatcher}" />

  <fileset dir="${web_directory}">
   <exclude name="WEB-INF/web.xml" />
  </fileset>
</war>
</target>

<target name="copy_dispatcher" depends="war_dispatcher" description="Copy 
dispatcher war to tomcat webapp directory">
   <copy file="${target}/Dispatcher.war" tofile="${tomcat}/Dispatcher.war" 
overwrite="true"/>
</target>

</project>

我的蚂蚁脚本编译我的类,创建war文件并将其复制到tomcat / webapp /文件夹中。

我还配置了catalina.sh使其能够接受如下的远程调试。

#
JPDA_OPTS="-
agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y"
#

最后,我在eclipse中使用端口8000和主机localhost设置了一个远程Java应用程序。当我运行http://localhost:8080/Dispatcher/BackTest时,可以看到我的Hello单词出现,但是eclipse不会在我设置的断点处停止doGet。我还尝试使用jdb作为调试器,认为这是一个日食问题,但我看不到代码:

alex@XXX:~/alx_git/orderManager$ jdb -attach localhost:8000 -sourcepath 
src/dispatcher/ 
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
> stop in alxFinancial.dispatcher.BackTest.doGet
Set breakpoint alxFinancial.dispatcher.BackTest.doGet
> 
Breakpoint hit: "thread=http-nio-8080-exec-5", 
alxFinancial.dispatcher.BackTest.doGet(), line=23 bci=0

http-nio-8080-exec-5[1] next 
> 
Step completed: "thread=http-nio-8080-exec-5", 
alxFinancial.dispatcher.BackTest.doGet(), line=24 bci=8

http-nio-8080-exec-5[1] next 
> 
Step completed: "thread=http-nio-8080-exec-5", 
alxFinancial.dispatcher.BackTest.doGet(), line=25 bci=15

我为大家提供了有关ant,javac,java,eclipse和tomcat版本的更多信息。

ant Apache Ant(TM) version 1.10.3 compiled on March 24 2018
javac javac 1.8.0_131

java java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)


eclipse Version: Neon.3 Release (4.6.3)
Build id: 20170314-1500

Server version: Apache Tomcat/8.0.24
Server built:   Jul 1 2015 20:19:55 UTC
Server number:  8.0.24.0
OS Name:        Linux
OS Version:     4.15.0-34-generic
Architecture:   amd64
JVM Version:    1.8.0_131-b11
JVM Vendor:     Oracle Corporation

我真的很抱歉提出这个问题,但是我被困住了。我之前确实尝试过,但是无法调试我的代码。

我现在越来越近了。如果创建一个Java动态Web项目,请在其中包含我的BackTest.java类,并将War File导出到我的tomcat服务器,它可以工作,我可以在断点处停止。而如果我将新的Java项目与现有的ant构建文件一起使用,则无法通过Eclipse对其进行调试。 WAR文件中可能缺少某些库吗? 我希望你能帮助我。 亚历克斯

0 个答案:

没有答案