2

I'm a novice here in maven, I'm trying to shade my plugin to add dependencies in my project. But I can't seems to find a way to use maven shade plugin. I would ask that anyone here would show me some examples and explain for me specifically, thanks.

geraldhumphries
  • 1,493
  • 12
  • 27
Woo E-Than
  • 21
  • 1
  • 2
  • Can you add some examples of what you've tried? – geraldhumphries Jun 12 '16 at 03:25
  • I don't understand actually. Do I have to directly create a pom.xml or create a maven project and the thing is pom.xml in eclipse is different from others. Btw I'm using Eclipse Mars. May your guidance lead my way – Woo E-Than Jun 12 '16 at 03:41
  • If you are using maven then you need a `pom.xml` file. Eclipse will generate one for you, or you can create one from scratch, but for the purpose of your question it doesn't matter. – geraldhumphries Jun 12 '16 at 03:46
  • As stated I have no idea how to maven shade my java project with adding dependencies so I can load them without noclassdeffounderror. – Woo E-Than Jun 12 '16 at 03:48

1 Answers1

1

Generally plugins are added to the plugins section of your pom.xml. You need to specify the groupId, artifactId, and version of the plugin you are trying to use. For maven-shade-plugin, you can import it in your pom like this:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <configuration>
          <!-- put your configurations here -->
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

This will bind the goals for the Shade plugin to the package phase. Running mvn package will produce a shaded JAR.

Source: https://maven.apache.org/plugins/maven-shade-plugin/usage.html

You can view more examples in the links at the bottom of this page: https://maven.apache.org/plugins/maven-shade-plugin/index.html

geraldhumphries
  • 1,493
  • 12
  • 27