Java remote debugging with docker container | IntelliJ

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] I'm going to show you how we can make a remote debugging of a Java application in this example I'm going to show you how we can create a Docker image and create a Docker container of our Java application and how we can connect our IntelliJ AG into this container running our Java application for today we are going to choose a API rest that I developed we are going to call this endpoint that is API V1 users this one is going to to call a service class and what we want to debug is the line 14. so we will just want to check if this parameter is empty or not this parameter as you can see we are using add value annotation that is we map a value in the application emo file to our code sometimes we use this mapping in the case that we want to change the value and we don't want to create a new deploy of our Java application so we only need to change this value in our Docker or kubernetes environment in our tests we are going to say that someone forgot to add this value in our kubernetes Docker environment and we want to see if it is is empty or not so this is going to be the goal for our test today for the for us achieve a remote debugging in a Java application is first choose the day gwp that is dejava the bug while protocol with this command as you can see here is a Java common we are going to expose a certain part that in our case is going to be the 8 000 part and also we are going to use the jar bio that we generate using the amazing dependency to as you can see here we set this Java command in a entry point sh file that we are going to call with our Docker file as you can see here our Docker file we are using this image for the Java jdk17 and we we are exposing two parts first one is it 8080 that is related with the entry point of our application and the second one is the same that we declare in the entry point sh file that is going to be the part that we're going to use for the remote debugging as I said before we are going to use the jar file that we are going to generate in our application so this this is why we are taking the local file and moving to our Docker image and also we are going to to send the sh file itself as well and after we are going to choose we're going to execute this sh file in the entry point key now let's create our Docker image first we're going to build our Docker file is going to be the tag that I'm going to give also the version 1.0 that's it and now we're going to run a Docker container using that image as you can see here we also expose the two parts the 8080 as I said for the entry point and 8000 for the remote debugging if we check is powerpods our container is running we can see here that it's up in seven seconds so now what we need to do is when using the IntelliJ we can we can came here into for example edit configurations and normally when you're going to open this page you're going to see the application uh selected this option usually you're going to run a pointy to your main class that in my case is the remote debug application but what you can do is you can click in the plus sign here and what we're going to add is the remote jvm debug with that we're going to use this new option to point to our application that is running inside a Docker container so as you can see here as I'm running the docker container in my localhost I set the localhost and the part 8000. so this is all that I need also we are using suspend Eco n this means that we are going to execute our application and we are not going to wait for some application uh started debugging we are going to like execute automatically so if I make an apply here and click in the debug bottle you see that we are connected to the Target virtual machine with the localhost and 8000 part so we are not running this locally yes we are running locally using our Docker container now to see if it's working we're going to choose our service class we are going to set just a breakpoint on line 14 we are going to use the postman to call our API and when we make a call you see that this is working we are using our Java application running in our Docker environment we are not running anything in our IntelliJ IntelliJ now is just a client for our Java Docker application in resume the way that we can achieve the remote body for a Java application is using the jwp moment as you can see here we have a different variations of this command if you you are using Java 9 plus you when you can use like this way of the command that the same that we use here we just use we can set um our jar application here in front of the part number if you are using Java 5 is a different way and also you as you can see we can instead of using the jar file you can use your main application so I'm going to leave the links for this different options in the description of the video so you can go for the solution that that works better for you thanks and see you soon
Info
Channel: Woodstack
Views: 513
Rating: undefined out of 5
Keywords: java, docker, debug, software
Id: Aam-XZbIuJ4
Channel Id: undefined
Length: 8min 13sec (493 seconds)
Published: Fri Sep 15 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.