Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coc-java-debug for tomcat7 in docker #8

Closed
fedoranvar opened this issue Aug 18, 2020 · 7 comments
Closed

coc-java-debug for tomcat7 in docker #8

fedoranvar opened this issue Aug 18, 2020 · 7 comments
Labels
question Further information is requested

Comments

@fedoranvar
Copy link

fedoranvar commented Aug 18, 2020

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:
neoclide/coc-java#99 (comment)

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
Copy link
Owner

dansomething commented Aug 18, 2020

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"
        }
      }
    }
  }
}

@dansomething dansomething added the question Further information is requested label Aug 18, 2020
@fedoranvar
Copy link
Author

@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:
0. mvn clean package and move ROOT.WAR file to tomcat folder

  1. Run docker container
  2. Put breakpoint in code
  3. run CocCommand java.debug...
  4. 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
Copy link
Owner

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
Copy link
Author

fedoranvar commented Aug 19, 2020

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

@dansomething

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

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants