I have a project with 2 maven plugin.
In docker container, tomee and mysql runs. I want to debug java with the front-end which means by hitting http://localhost:8080/mywebapp
, the system should stop at the break point I set in backend (java file). I am using IntelliJ.
Does somebody know how to do it?
Since you are running you application in docker container remote debugging is the only way. you could,
http://localhost:8080/mywebapp
. with Gauraj's suggestions I have modified the 3 files: 1. docker-compose.yml:
version: '2.0'
services:
db:
build: 04.MySQL/
tomee:
build: .
depends_on:
- db
command: >
/bin/bash -c "
while ! nc -z db 3306;
do
echo sleeping;
sleep 5;
done;
echo Connected!;
catalina.sh run;
"
links:
- db:db
ports:
- "8080:8080"
- "8000:8000"
ssl:
build: 05.ProxySSL/
links:
- tomee
ports:
- "443:443"
- "80:80"
2. Dockerfile:
FROM java:8-jdk
MAINTAINER "Software Engineering, RWTH Aachen University"
ENV PATH /usr/local/tomee/bin:$PATH
RUN mkdir -p /usr/local/tomee
WORKDIR /usr/local/tomee
# curl -fsSL 'https://www.apache.org/dist/tomee/KEYS' | awk -F ' = ' '$1 ~ /^ +Key fingerprint$/ { gsub(" ", "", $2); print $2 }' | sort -u
ENV GPG_KEYS \
BDD0BBEB753192957EFC5F896A62FC8EF17D8FEF \
223D3A74B068ECA354DC385CE126833F9CF64915 \
7A2744A8A9AAF063C23EB7868EBE7DBE8D050EEF \
82D8419BA697F0E7FB85916EE91287822FDB81B1 \
9056B710F1E332780DE7AF34CBAEBE39A46C4CA1 \
A57DAF81C1B69921F4BA8723A8DE0A4DB863A7C1 \
B7574789F5018690043E6DD9C212662E12F3E1DD \
B8B301E6105DF628076BD92C5483E55897ABD9B9 \
DBCCD103B8B24F86FFAAB025C8BB472CD297D428 \
F067B8140F5DD80E1D3B5D92318242FE9A0B1183 \
FAA603D58B1BA4EDF65896D0ED340E0E6D545F97
RUN set -xe \
&& for key in $GPG_KEYS; do \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
done
RUN set -x \
&& curl -fSL https://dist.apache.org/repos/dist/release/tomee/tomee-1.7.4/apache-tomee-1.7.4-plus.tar.gz.asc -o tomee.tar.gz.asc \
&& curl -fSL http://apache.rediris.es/tomee/tomee-1.7.4/apache-tomee-1.7.4-plus.tar.gz -o tomee.tar.gz \
&& gpg --batch --verify tomee.tar.gz.asc tomee.tar.gz \
&& tar -zxf tomee.tar.gz \
&& mv apache-tomee-plus-1.7.4/* /usr/local/tomee \
&& rm -Rf apache-tomee-plus-1.7.4 \
&& rm bin/*.bat \
&& rm tomee.tar.gz*
RUN apt update && apt install -y netcat-openbsd
RUN mkdir -p /usr/local/tomee/webapps
COPY 03.dockerconfig/tomcat-users.xml /usr/local/tomee/conf/
COPY 01.Backend/lib/ /usr/local/tomee/lib/
COPY 01.Backend/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar /usr/local/tomee/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar
COPY 01.Backend/target/macoco-be.war /usr/local/tomee/webapps/macoco-be.war
COPY 02.Frontend/MaCoCoLive/target/MaCoCoLive.war /usr/local/tomee/webapps/MaCoCoLive.war
COPY 01.Backend/target/apache-tomee/bin/catalina.sh /usr/local/tomee/bin/catalina.sh
EXPOSE 8080 4200 8000
CMD ["catalina.sh", "jpda run"]
catalina.sh file:
JPDA_SUSPEND="y"
JDPA_OPTS -agentlib:jdwp=transport=dt_socket, address=8000,server=y,suspend=$JPDA_SUSPEND
my remote debug configuration:
Then in I run "docker-compose build" and "docker-compose up". But when I debug it, IntelliJ shows error: "Unable to open debugger port (localhost:8000):java.io.IOException "handshake failed - connection permaturally closed."
just now I have figured out how to make it in Netbeans!
I think remote debug TomEE inside Docker in IntelliJ is impossible because the IntelliJ try to access catalina.sh inside Docker image which is not permitted by docker. But in Netbeans the server is integrated with IDE so it doesn't need to access catalina.sh.
What I do is a little tricky: first run "mvn clean install docker:stop docker:start -DskipTests tomee:run" then I have the Tomee server inside docker started. Then add this TomEE server to Netbeans (each time after rerun the mvn command, I need to add this server again).
Then just make break point and debug the maven project.
After that port8080 is occupied by Netbeans so that I cannot access localhost:8080. But I can run "npm start" to start front end in Port4200 then by every action in front end it will stop at the break point in backend.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.