Search code examples
javaantenunciate

Unable to create enunciate java client using ant task


I am attempting to create the java-client library using an enunciate v1.26.2 ant task. The problem is that every time I attempt to do this, I get this warning message:

WARNING: Unknown artifact 'java.client.library'.  Artifact will not be exported.

I've checked that the java-client enunciate jar is on the class path and enunciate even says that it has found it in the output.

enun:
Loading modules from the specified classpath....
Discovered module docs
Discovered module java-client
...

So I'm not sure what to do exactly. I have tried googling to find that SO only has a few questions for enunciate, and none seem to answer my question. This is my ant script with relevant lines:

<path id="enunciate.classpath">
    <fileset dir="${lib.enunciate.dir}">
        <include name="*.jar"/>
    </fileset>
    <fileset dir="${lib.dir}">
        <include name="**/*.jar" />
    </fileset>
    <fileset dir="${java.home}">
        <include name="lib/tools.jar"/>
    </fileset>
</path>

<taskdef name="enunciate" classname="org.codehaus.enunciate.main.EnunciateTask">
    <classpath refid="enunciate.classpath"/>
</taskdef>

<target name="enun" description="Run enunicate task on the rest services">
    <enunciate basedir="${src.web.java.dir}">
        <include name="**/*.java"/>
        <classpath refid="enunciate.classpath"/>
        <export artifactId="java.client.library" destination="${dist.client.dir}/rest/" />
        <export artifactId="docs" destination="${dist.docs.rest.dir}/"/>
        <javacArgument argument="-g"/>
    </enunciate>
</target>

Note: The docs export gets called and exports correctly with no problems. The code that is included compiles with no problem. I just can't seem to discover why the ant script doesn't want to export the java-client library. I've tried changing the name of the artifactId to several different values, including: java.client.library.binaries, java-client.library, enunciate-java-client, and all manner of other things with no end result. I have tried to use an enunciate.xml config file, which didn't seem to help. Here is the xml I tried to use:

<?xml version="1.0"?>
<enunciate label="full" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">
    <modules>
        <java-client disabled="false" disableCompile="false" jarName="foo.jar"/>
        <docs disabled="false" docsDir="dist/docs/rest/"/>
    </modules>
</enunciate>

Solution

  • tl;dr: For my project I can only use enunciate's docs function because I don't have JAXB/Jackson set up on the rest service's domain objects. I use something different which just passes along JSON strings, which enunciate doesn't recognize as a valid endpoint return/accept type and so cannot create a client API.

    So after an exhaustive search and analysis of enunciate I realized that I had made some assumptions about it that led me to a bad path. I'm gonna share my findings here incase this helps anyone else along the way.

    Among my mistakes are the fact that I only skimmed enunciate's website the first time and it didn't quite click what enunciate's goals were. Enunciate is a library that attempts to make creating a rest API much much easier. However, working within a rest API already made can be tricky. In my case, the rest service is so massive that making large changes would be impossible.

    The biggest realization that I had: enunciate requires you to have some sort of endpoint return/accept type that enunciate can recognize. So, JAXB, Jackson, etc... Without these things enunciate essentially says, "I have no way to make a client API since I don't know what your endpoints are returning/accepting." It therefore refuses. I tested this by checking my code vs. the enunciate examples and the POJO examples have @XmlRootElemet from JAXB on their domain POJOs. This allows the rest services to pass them around and JAXB handles the (un/)marshalling. Enunciate then makes a client API with POJOs that can handle the data that the endpoint hands it. (Might even just be direct copies of the POJOs, I haven't confirmed this though.)

    (Hopefully my understanding of this process is correct. Please comment if it isn't and I will make appropriate edits.)

    I hope this helps someone else out there.