java远程调试
idea2024创一个Spring Web项目springdemo1
使用maven-assembly-plugin插件打包成JAR文件
pom.xml参考如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
</parent>
<groupId>com.jk</groupId>
<artifactId>Springdemo1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Springdemo1</name>
<description>Springdemo1</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.jk.springdemo1.Springdemo1Application</mainClass>
<!-- 这里要输入mainClass的地址 -->
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
com.jk.springdemo1/controller/hellocontroller.java
package com.jk.springdemo1.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class hellocontroller{
@RequestMapping(value="/",method = RequestMethod.GET)
public String index(@RequestParam(value="name",required = false,defaultValue = "lihua") String name){
System.out.println("hello");
return "HelloWorld,"+name;
}
}
idea终端输入mvn package
开始打包
PS:可以把生成的jar文件放入lib目录下,右键->add as library,之后再项目其他位置import就可以用了。
下面把Springdemo1-0.0.1-SNAPSHOT.jar拖进kali虚拟机
idea添加Remote JVM Debug,Host填虚拟机ip
kali
java -version
sudo su
update-alternatives --config java #切换jdk版本到jdk11
java -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:9988 -jar Springdemo1*
idea开启debug,本机访问网址,可以看到程序断在了断点处