Search code examples
javamavenmaven-2maven-shade-plugin

ClassNotFound exception while using the Maven Shade Plugin


I am trying to follow this link: http://maven.apache.org/plugins/maven-shade-plugin/examples.html

I am new to Maven. I feel a bit out of depth trying to follow the example.

I am able to get Quartz Scheduler to get working with Spring. I want to be able to run it from commandline using jar file.

Here are the list of classes and pom file I used.

shade maven plugin

EDIT:

I am able to get a shade jar file. I used mvn clean install

but when I try to run it from the command line, I get the following errors.

C:\Users\SpringExample\target>java -jar SpringExample-1.0-SNA PSHOT-shaded.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/sonatype/haven/Ex odusCli Caused by: java.lang.ClassNotFoundException: org.sonatype.haven.ExodusCli at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: org.sonatype.haven.ExodusCli. Program will exit.

EDIT2:

I used the following in the pom above using this link:

http://seanfreitag.wordpress.com/2011/07/25/create-an-executable-jar-with-dependencies-using-maven/

 <project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.4</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Main-Class>org.sonatype.haven.ExodusCli</Main-Class>
                    <Build-Number>123</Build-Number>
                  </manifestEntries>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/spring.handlers</resource>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/spring.schemas</resource>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

Solution

  • I haven't used Shade, but I suspect that:

    • the pom that you are using to invoke Shade is not shown

    • the Maven example showing how to set a Main-Class assumes that the class org.sonatype.haven.HavenCli is somewhere in the jar being assembled

    • you have no such class

    • you should change the class name in your <mainClass>org.sonatype.haven.HavenCli</mainClass> to whatever you want to use as a main class