Maven项目JVM调试配置:依赖缺失与远程调试问题排查
Hey there, let's break down why you're hitting those NoClassDefFoundError issues and how to fix them—your setup with maven-shade-plugin for class relocation is the key piece here, and IntelliJ's default debug flow isn't playing nice with it. Let's dive in:
Why This Is Happening
Your project uses the maven-shade-plugin to relocate classes from com.cryptomorin.xseries to me.playbosswar.com, but when you debug directly through IntelliJ, it skips the Maven shade step entirely. That means the classes in your debug classpath still use the original package names, while your code is referencing the relocated ones—hence the missing class errors. Also, your YAML resources need Maven's resource filtering to end up in the right place for debugging, which IntelliJ's default build doesn't handle properly.
Step 1: Tie Your Debug Configuration to Maven's Build Lifecycle
You need to make sure IntelliJ runs the necessary Maven goals before starting the debug session:
- Go to Run > Edit Configurations
- Create or edit your Remote JVM Debug setup (make sure the port matches your local server's debug port, usually 5005)
- In the Before Launch section, click the
+button and select Run Maven Goal - Enter the goal:
clean compile shade:shade- This tells IntelliJ to clean old builds, compile your code, and run the shade plugin to handle class relocation and package dependencies before connecting to the remote JVM
- Save the configuration
Step 2: Make IntelliJ Use Maven's Output Directory
To ensure you're using the Maven-processed classes (with relocated packages) instead of IntelliJ's own compiled versions:
- Open File > Project Structure > Modules
- Select your project module, go to the Paths tab
- Set the Compile output paths to match Maven's defaults:
- Production output:
target/classes - Test output:
target/test-classes
- Production output:
- Apply the changes—now IntelliJ will use the classes generated by Maven, not its own
Step 3: Ensure YAML Resources Are Loaded Correctly
Your POM already has the resources configuration set up with filtering, so running the Maven goal from Step 1 will automatically copy and process your YAML files into target/classes. If you ever need to verify:
- Run
mvn resources:resourcesmanually from the terminal or IntelliJ's Maven panel - Check the
target/classesdirectory to confirm your YAML files are present
Step 4: Test the Debug Flow
- Start your local Minecraft server with remote debugging enabled—your server startup command should include:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar server.jar - Launch your configured Remote Debug session in IntelliJ—wait for Maven to finish building, then confirm the debug connection is established
- Test your plugin functionality—those
NoClassDefFoundErrorshould be gone, and your YAML resources should load properly
Quick Extra Tips
- The
providedscoped dependencies (likepaper-apiandplaceholderapi) are fine—they're already present on the server, so they don't need to be shaded or included in your debug classpath - If you want to skip Jar packaging during debug (to save time), you can tweak the Maven goal to
compile shade:shade -Dmaven.jar.skip=true—this still runs the class relocation without generating the final Jar - If you run into issues, check the IntelliJ Run console to make sure the Maven goals executed without errors—any shade plugin failures will show up there
内容的提问来源于stack exchange,提问作者Trisma




