gpt4 book ai didi

java - IntelliJ 在 Docker 中调试 Java 应用程序

转载 作者:行者123 更新时间:2023-11-30 05:31:42 26 4
gpt4 key购买 nike

我对此很陌生。您能告诉我如何设置在 Docker 中运行的调试 Java 程序吗?

该项目是在 Maven 的帮助下构建的,之后 Docker 使用 *.war 来运行该程序。据我了解,IntelliJ必须远程推送才能调试。

container

docker-compose.yml:

# myapp (Wildfly + Keycloak + myapp)
myapp-myapp:
image: myapp/wildfly-myapp:wf11
container_name: myapp-myapp
depends_on:
- myapp-postgres
- myapp-mailhog
environment:
TZ : Europe/Paris
KEYCLOAK_URL: http://localhost:8080/auth
WILDFLY_PROXY_ADDRESS_FORWARDING: "true"
JAVA_OPTS:
DB_CONNEXION_URL: jdbc:postgresql://myapp-postgres:5432/myapp_db
DB_CONNEXION_URL_DELIMITER: "|"
DB_HOST: myapp-postgres
DB_NAME: ${DB_NAME}
DB_PASSWORD: ${DB_PASSWORD}
DB_USER: ${DB_USER}
KEYCLOAK_DB_CONNEXION_URL: jdbc:postgresql://myapp-postgres:5432/keycloak
KEYCLOAK_DB_CONNEXION_URL_DELIMITER: "|"
KEYCLOAK_DB_USER : keycloak
KEYCLOAK_DB_PASSWORD : keycloak
KEYCLOAK_DB_NAME : keycloak
KEYCLOAK_DB_HOST: postgres
APP_CLUSTER: "false"
JGROUPS_EXTERNAL_ADDRESS: 10.178.27.30
JGROUPS_TCP_EXTERNAL_PORT: 7600
JGROUPS_TCP_BIND_PORT: 7600
JGROUPS_DEFAULT_STACK: tcpping
JGROUPS_INITIAL_HOSTS: "10.178.27.30[7600]"
WILDFLY_CLUSTER_PASSWORD:
WILDFLY_NODE_NAME: myapp-master
SMTP_HOST: myapp-mailhog
SMTP_PORT: 1025
SMTP_FROM: ${SMTP_FROM}
SMTP_USERNAME: ""
SMTP_PASSWORD: ""
myapp_LOG_LEVEL: "ALL"
myapp_DEBUG_LEVEL: "ALL"
volumes:
- ./myapp/data:/opt/jboss/myappdata
- ./myapp/logs:/opt/jboss/wildfly/standalone/log
- ./myapp/deployments:/opt/jboss/wildfly/standalone/deployments
- ./myapp/configuration/myapp-admin.properties:/opt/jboss/wildfly/standalone/configuration/myapp-admin.properties
- ${ST_SRC}:/opt/jboss/myappdata/${PROVIDER_CODE}/frontend/st
- ${CC_SRC}:/opt/jboss/myappdata/${PROVIDER_CODE}/frontend/cc
- ${SC_SRC}:/opt/jboss/myappdata/${PROVIDER_CODE}/frontend/sc
ports:
- "8080:8080"
- "7600:7600"

最佳答案

您可以使用以下 JVM 参数启用远程调试

-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n

然后您可以使用 Run -> Attach to process 附加 Intellij 调试器您的应用程序应该指定端口(在本例中为 8000)

参见here了解更多信息

对于此示例(Docker-Compose 与 Wildfly)

environment:
...
JAVA_OPTS: -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n
...
ports:
- "8000:8000"
...

一般情况

Docker

要在 Docker 中使用,您还必须公开端口

EXPOSE 8000
ENTRYPOINT ["java", "-jar", "-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n", "/path/to/my/java.jar"]

然后

docker run -p 8000:8000 <image>

IntelliJ(从 2019.1 开始)

此过程现在可以由 IntelliJ 自动完成 https://blog.jetbrains.com/idea/2019/04/debug-your-java-applications-in-docker-using-intellij-idea/

关于java - IntelliJ 在 Docker 中调试 Java 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57395597/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com