Maven构建Jar包运行时exec-maven-plugin执行失败求助
Hey there, sorry you're stuck with this frustrating exec-maven-plugin issue—partial error messages like that are always such a tease! Since you’ve already combed through Stack Overflow and GitHub without luck, let’s break this down with targeted checks and fixes that might have slipped through the cracks.
First, Let’s Grab the Critical Missing Details
That error cut off right when it was about to tell us the actual problem. To diagnose this properly, could you share:
- The full error stack trace (especially the
Caused by:section—this is almost always the root cause) - The exact Maven command you’re running (e.g.,
mvn exec:javaormvn exec:java -Dexec.mainClass=com.your.app.Main) - The snippet of your
pom.xmlwhere theexec-maven-pluginis configured
Targeted Fixes to Try Immediately
Even without the full details, here are some common fixes that resolve this exact plugin failure:
1. Double-Check Your Main Class Configuration
The most common culprit is a missing or incorrect main class definition.
- If you’re configuring it in
pom.xml, make sure the path is fully qualified (including the package):<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.6.0</version> <configuration> <mainClass>com.your.package.YourActualMainClass</mainClass> </configuration> </plugin> - If you’re passing it via the command line, ensure there are no typos:
mvn exec:java -Dexec.mainClass=com.your.package.YourActualMainClass
2. Fix Dependency Scope Issues
If your main class relies on dependencies marked as provided or test, the exec plugin won’t include them in the classpath by default. Add this to your plugin configuration to force including compile-scoped dependencies:
<configuration> <mainClass>com.your.package.YourActualMainClass</mainClass> <includeScope>compile</includeScope> </configuration>
3. Clean and Rebuild to Clear Cached Junk
Corrupted class files or cached artifacts often cause weird plugin failures. Run these commands in order:
mvn clean mvn package mvn exec:java
4. Upgrade the Exec Plugin Version
Version 1.6.0 is pretty old (released in 2017) and has known compatibility issues with newer Maven (3.8+) and Java (11+) versions. Try upgrading to the latest stable version (as of 2024, that’s 3.1.0):
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>3.1.0</version> <configuration> <mainClass>com.your.package.YourActualMainClass</mainClass> </configuration> </plugin>
5. Verify Java Version Mismatches
Make sure the Java version Maven is using matches what you compiled your project with. Run mvn -v to check the runtime Java version, then confirm it matches the source and target in your pom.xml:
<properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> </properties>
If None of These Work...
Drop the full error log, your plugin configuration, and the command you’re running, and we’ll dig into the exact root cause—whether it’s a missing dependency, permission issue, or something more obscure.
内容的提问来源于stack exchange,提问作者Rohith Joseph

