为何无法构建可执行Maven项目?RDF2Vec Jar报主清单属性缺失
I get it—nothing's more frustrating than a clean Maven build that throws a runtime error because the JVM can't find your entry point. That "no main manifest attribute" error pops up exactly because Maven didn't flag your WalkGenerator class as the executable's starting point in the JAR's manifest.
Why This Happens
When you build a JAR with Maven, the default setup doesn't add a Main-Class attribute to the manifest file. Without this, the JVM has no clue which class to run when you execute java -jar your-rdf2vec.jar, even if your code is perfectly valid.
Your Fix, Explained (And Polished)
Your instinct to update the manifest configuration was spot-on. Here's how to properly implement it in your pom.xml to make walks.WalkGenerator the default main class, while also handling dependency classpaths:
- Find (or add) the
maven-jar-pluginsection inside your<build><plugins>block. - Update its configuration to include the manifest settings with both
addClasspathandmainClass:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.3.0</version> <!-- Use the latest stable version --> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>walks.WalkGenerator</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build>
Quick Tips to Avoid Headaches
- Double-check the class path: Make sure
walks.WalkGeneratoris the full, correct package path of your class—no typos here! - Rebuild cleanly: After updating the
pom.xml, runmvn clean packageto generate a fresh JAR with the updated manifest. - Verify the manifest: You can peek inside the JAR's
META-INF/MANIFEST.MFfile to confirm it has lines like:Main-Class: walks.WalkGenerator Class-Path: [list of your project dependencies]
Once you do this, running java -jar your-generated-jar.jar should launch WalkGenerator without that annoying manifest error.
内容的提问来源于stack exchange,提问作者rajiv.v.i

