简体   繁体   中英

How can I debug efficiently in java when I'm using curl?

I'm using Maven/Jetty to run my app and sending post requests to it.

$mvn jetty:run
$curl -H "Content-Type:application/json" -XPOST 'http://localhost:8080/hi' -d '{"url":"http://www.subway.com", "operator":1}

Here is an example of my class. It is using RestEasy to hook everything up so that the curl to localhost:8080/hi causes handlePost() to be called:

@Path("/hi")
public class Hi {
    @POST
    @Consumes("application/json")
    @Produces("text/plain")
    public Response handlePost() {
        return Response.status(HttpStatus.SC_OK).entity("hey!").build();
    }
}

Note this will output

"hey!" 

I want to be able to debug my code efficiently, and was wondering if there is a way to

  1. Make breakpoints work and debug with IDE (using IntelliJ)
  2. Output something simple to the terminal

For #1, I'm not sure where to start. For #2, I tried

System.out.println("hello!");

but it never gets outputted, presumably because I'm not running my program from the terminal?

Instead of using mvn jetty:run to launch your Web application from the command line, launch your application from your IDE. It should attach a debugger and allow you to use your standard tools. The client you use to talk to the application doesn't matter, so curl will work just fine.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM