dansomething / coc-java-debug

An extension for coc.nvim to enable Java debugging via jdt.ls
https://www.npmjs.com/package/coc-java-debug
Eclipse Public License 2.0
100 stars 8 forks source link

coc-java-debug for tomcat7 in docker #8

Closed fedoranvar closed 4 years ago

fedoranvar commented 4 years ago

Good day to you!

I have java spring application that runs in docker-container (tomcat7) and I want to debug it from vim.

here is my docker-compose.yml for java app :

version: '3'
services:
    java-tomcat:
        build:
            context: ../_bin/${JAVA_VERSION}
        container_name: "${CONTAINER_NAME}"
        restart: always
        volumes:
          - ${DOCUMENT_ROOT}/WAR:/usr/local/tomcat/webapps/
          - ${TOMCAT_CONF}:/usr/local/tomcat/conf/
        environment:
              ENV JPDA_ADDRESS: "8000"
              ENV JPDA_TRANSPORT: "dt_socket"
        networks: 
            - lamp
        ports:
            - 8888:8080
            - 9000:8000
        labels:
          - "traefik.enable=true"
          - "traefik.http.routers.${CONTAINER_NAME}.rule=Host(`${CONTAINER_NAME}.docker.localhost`)"
          - "traeeik.http.routers.${CONTAINER_NAME}.entrypoints=web"

networks:
    lamp:
        external: true

my .vimspector.json:

{
  "adapters": {
    "java-debug-server": {
      "name": "vscode-java",
      "port": "${AdapterPort}"
      }
  },
  "configurations": {
    "Java Attach": {
      "adapter": "java-debug-server",
      "configuration": {
        "request": "attach",
        "host": "localhost",
        "port": "5005"
      },
      "breakpoints": {
        "exception": {
          "caught": "N",
          "uncaught": "N"
        }
      }
    }
  }
}

after container runs I'm calling :CocCommand java.debug.vimspector.start and m after that it loads hangs in 'Attaching in debugee...' image

Before that I've had a problem with running java server and it was resolved by using answer: https://github.com/neoclide/coc-java/issues/99#issuecomment-663856695

My thoughts, that I have incorrect .vimspector.json config, but at the moment can't figure out what to do. Will appreciate any help!

Thanks!

dansomething commented 4 years ago

Based on the Docker configuration you provided, it looks like you're mapping your host port 9000 to the Java debugger on port 8000 in the container. In that case it would be my expectation to set your "Java Attach" port to 9000 in your .vimspector.json file instead of 5005.

{
  "adapters": {
    "java-debug-server": {
      "name": "vscode-java",
      "port": "${AdapterPort}"
      }
  },
  "configurations": {
    "Java Attach": {
      "adapter": "java-debug-server",
      "configuration": {
        "request": "attach",
        "host": "localhost",
        "port": "9000"
      },
      "breakpoints": {
        "exception": {
          "caught": "N",
          "uncaught": "N"
        }
      }
    }
  }
}
fedoranvar commented 4 years ago

@dansomething I've changed port to 9000, but no luck image

it hangs on Connecting to localhost: .... he can't connect to Adapter?

My steps:

  1. mvn clean package and move ROOT.WAR file to tomcat folder
  2. Run docker container
  3. Put breakpoint in code
  4. run CocCommand java.debug...
  5. Open page (localwhere breakpoint should be trigerred

here is my docker inspect output image

maybe there is something in Maven?

To ensure that application is debugable: Before moving to neovim, I was able to debug this app in vscode.

Thanks!

dansomething commented 4 years ago

It does seem like Vimspector may not be connecting to the Java debug server "Adapter". When you debugged it from vscode, what Java debug port did you attach to? Also, what do you see in Vim when you run :messages after you've started the debugger? For example, after I run :CocCommand java.debug.vimspector.start I see the following messages:

[coc.nvim] Starting Java debug server...
[coc.nvim] Java debug server started on port: 52737
[coc.nvim] Launching Vimspector with settings: {"AdapterPort":52737}
Paused in thread 1 due to breakpoint
fedoranvar commented 4 years ago

Also, what do you see in Vim when you run :messages after you've started the debugger?

image

When you debugged it from vscode, what Java debug port did you attach to?

here is Server configuration file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/>
  <Listener className="org.apache.catalina.core.JasperListener"/>
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml"/>
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>
      <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b"/>
      </Host>
    </Engine>
  </Service>
</Server>

for debugging in vscode no launch.json need

I've realised that I was using tomcat-server debugger in vscode, not vscode-java-debug

dansomething commented 4 years ago

It does look like your Vim is connecting to the debug adapter server since it got a port and is passing that to Vimspector. Its possible Vimspector isn't able to connect to that port, but its unclear why. Are you able to debug a Java project that isn't running in Tomcat or Docker?

dansomething commented 4 years ago

Another thing I noticed, and I'm not that familiar with Docker Compose, is it looks like the way you're defining Environment in docker-compose.yaml doesn't resemble the documented configuration format. Can you confirm it is correctly setting those environment options in the container for Tomcat?

Based on the Docker compose docs I'd expect your config to look like:

        environment:
          - JPDA_ADDRESS=8000
          - JPDA_TRANSPORT=dt_socket
fedoranvar commented 4 years ago

@dansomething

You were right: It was the problem with the environment variables in docker compose.

Thank you!