I have a project where compiling locally works, but deployment fails on the server. I want to know how to fix the "no main manifest attribute" error when trying to run a Java JAR file that was generated via a CI/CD pipeline. Should I use the assembly plugin or the standard shade plugin?
3 answers
When you need to build a fat JAR that contains all dependencies alongside your main class, the Maven Shade Plugin is actually an exceptional choice. It packages all dependency classes directly into a single archive and gives you an explicit configuration block to define your application entry point. By adding the Transformer implementation for the manifest resource inside the plugin configuration, Maven automatically writes the correct entry point attribute. This avoids any path errors on your deployment servers.
That makes sense for applications with external dependencies, but what if my project is just core Java code? Won't the shade plugin add unnecessary overhead and bloat the file size during our automated server builds?
If you are using Spring Boot, the framework provides its own specialized build plugin that configures the executable headers automatically during compilation.
I completely agree, Sandra. The Spring Boot Maven plugin handles the layout properties flawlessly under the hood, making it the fastest possible way to deploy web applications without worrying about manual metadata scripting.
You are completely right, Andrew. For standalone projects, the shade plugin is total overkill. Instead, use the basic maven-jar-plugin. It allows you to specify the main class inside the configuration archive block without bundling external libraries, keeping your final executable file incredibly small and lightweight.