Skip to content

Maven Client Side Artifacts

Ryan Heaton edited this page Jul 2, 2024 · 30 revisions

Client-Side Artifacts and Maven

It's great that Enunciate generates client code to access your Web service API, and it's nice that those artifacts can be accessed from the downloads page of the generated documentation. But let's say you're using Maven and you'd like to make those generated client-side artifacts available through a Maven repository. That way any Maven users that want to consume your client-side classes just have to declare a dependency in the pom.xml file.

Even though the maven-enunciate-plugin provides a way to "attach" any Enunciate artifacts (including client-side classes) to your project, this isn't as useful as this may sound. The problem is that artifacts that are "attached" to a Maven project inherit that project's pom. This means that even though the client-side artifact is available in a Maven repository, all the dependencies of the server-side artifact will be declared as dependencies for the client-side artifact.

Instead of attaching the client-side artifacts to the project, a better solution would be to deploy the artifacts with their own (generated) pom. If you're using Enunciate 1.17 and above, there are maven goals provided to do this conveniently.

Using Enunciate 2

<project ...>

<build>
  <plugins>
    ...
      <plugin>
        <groupId>com.webcohesion.enunciate</groupId>
        <artifactId>enunciate-maven-plugin</artifactId>
        <version>2.18.1</version>
        <executions>
          <execution>
            <!-- the standard "assemble" goal -->
           <id>assemble</id>
            <goals>
              <goal>assemble</goal>
            </goals>
            <configuration>
              ...
            </configuration>
          </execution>
          <execution>
            <id>install-and-deploy</id>
            <goals>
              <!-- the "install-artifact" goal does a local install of the artifact -->
              <goal>install-artifact</goal>
              <!-- the "deploy-artifact" goal deploys the artifact -->
              <goal>deploy-artifact</goal>
            </goals>
            <configuration>
              <!-- the "enunciateArtifactId" element is the only thing required.
                   other options reflect those of the maven deploy plugin, and include
                   options to set the groupId, artifactId, version, classifier, pomFile
                   etc. However, suitable defaults will be supplied as necessary -->
              <enunciateArtifactId>java.xml.client.library</enunciateArtifactId>
            </configuration>
          </execution>
        </executions>
      </plugin>
     ...
  </plugins>
  ...
</build>
...
</project>

Using Enunciate 1.x

<project ...>

<build>
  <plugins>
    ...
      <plugin>
        <groupId>org.codehaus.enunciate</groupId>
        <artifactId>maven-enunciate-plugin</artifactId>
        <version>1.17</version>
        <executions>
          <execution>
            <!-- the standard "assemble" goal -->
           <id>assemble</id>
            <goals>
              <goal>assemble</goal>
            </goals>
            <configuration>
              ...
            </configuration>
          </execution>
          <execution>
            <id>install-and-deploy</id>
            <goals>
              <!-- the "install-artifact" goal does a local install of the artifact -->
              <goal>install-artifact</goal>
              <!-- the "deploy-artifact" goal deploys the artifact -->
              <goal>deploy-artifact</goal>
            </goals>
            <configuration>
              <!-- the "enunciateArtifactId" element is the only thing required.
                   other options reflect those of the maven deploy plugin, and include
                   options to set the groupId, artifactId, version, classifier, pomFile
                   etc. However, suitable defaults will be supplied as necessary -->
              <enunciateArtifactId>java.client.library</enunciateArtifactId>
            </configuration>
          </execution>
        </executions>
      </plugin>
     ...
  </plugins>
  ...
</build>
...
</project>
Clone this wiki locally