1

I have a java rest service client that I am packaging up using the maven-assembly-plugin. I am creating a zip file containing all of the dependencies plus a jar-with-dependencies. So I end up with:

my-client-1.2-bin.zip
my-client-1.2-jar-with-dependencies.jar

I have written a small test java app that calls the client so that I can test the dependencies. If I unzip the dependency zip and add all of the jars to the class path, I am able to use the client successfully. If I attempt to only add the jar-with-dependency to my class path, it fails unless I also add the RestEasy Jackson2Provider jar to my classpath. I have confirmed that the ResetEasy Jackson2Provider is available in the jar-with-dependency jar file.

Here is the relevent part of my pom:

  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <version>3.1.2.Final</version>
      <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jackson2-provider -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jackson2-provider</artifactId>
      <version>3.1.2.Final</version>
    <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-client -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-client</artifactId>
      <version>3.1.2.Final</version>
    <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxb-provider -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxb-provider</artifactId>
      <version>3.1.2.Final</version>
    <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs-services -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs-services</artifactId>
      <version>3.1.2.Final</version>
    <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpcore</artifactId>
      <version>4.4.6</version>
    <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.5.3</version>
    <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->
    <dependency>
      <groupId>org.jboss.logging</groupId>
      <artifactId>jboss-logging</artifactId>
      <version>3.3.1.Final</version>
    <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.jaxrs/jackson-jaxrs-base -->
    <dependency>
      <groupId>com.fasterxml.jackson.jaxrs</groupId>
      <artifactId>jackson-jaxrs-base</artifactId>
      <version>2.8.8</version>
    <scope>runtime</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <dependencySets>
            <dependencySet>
              <outputDirectory>lib</outputDirectory>
              <scope>runtime</scope>
            </dependencySet>
          </dependencySets>
          <descriptors>
            <descriptor>src/assembly/client.xml</descriptor>
          </descriptors>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <pluginRepositories>
    <pluginRepository>
      <id>onejar-maven-plugin.googlecode.com</id>
      <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
    </pluginRepository>
  </pluginRepositories>

src/assembly/client.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly
  xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
    http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
      http://maven.apache.org/xsd/assembly-1.1.2.xsd">

  <id>bin</id>
  <formats>
    <format>zip</format>
    <format>tar.gz</format>
  </formats>
  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>
SteveS
  • 1,008
  • 3
  • 18
  • 32

1 Answers1

1

I ran into a similar problem when using the shade plugin. This is because the transformers in the Metadata folder is overwritten by the shade/assembly plugins. I could resolve it by using the following

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>path.to.your.main.Class</mainClass>
                        </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>
                        <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                    </transformers>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

Aman J
  • 452
  • 4
  • 15