How do I make jar files available to ant in a Jenkins pipeline?

2.3k views Asked by At

I've put together a basic Jenkins pipeline and it does what I expect for the most part.

However, I'm using ant and it requires access to specific jar files. I've specified the build step like so:

stage('Build') {
  // Build the project
  env.PATH = "${tool 'ant'}/bin:${env.PATH}"
  sh 'ant -f dita-tools/build_all.xml -lib $WORKSPACE/dita-ot/lib:$WORKSPACE/dita-ot/lib/saxon'
 }

The build I run through this pipeline fails and generates the following error:

java.lang.ClassNotFoundException: org.dita.dost.module.GenMapAndTopicListModule

From what I can tell, this is due to ant not having access to dost.jar that is in the dita ot. I've tried defining this argument a number of ways including specifically referencing dost.jar (I have a number of jars to include) but every time it fails with the same error.

When I put together a stand-alone ant project in Jenkins, ant has no problem accessing the jar by way of the argument I provide above. Is there a better way for me to supply this argument/dependency in a pipeline?

UPDATE: I added an echo statement for the classpath to my build script and was able to verify that adding the jars to the classpath in the build script does in fact work. So, for all intents and purposes, ant has access to all the relevant base toolkit jars for the target but the error persists. At this point, it appears that the problem has something to do with how the jenkins pipeline works as opposed to the dita ot itself?

1

There are 1 answers

2
Stefan Jung On

I assume you use custom plugins, if yes, please make sure, you correctly defined your jars in the plugin.xml like so:

<feature extension="dita.conductor.lib.import" file="lib/my.jar"/>

UPDATE

java.lang.ClassNotFoundException: org.dita.dost.module.GenMapAndTopicListModule

This error means, that the main DITA-OT jar is not found on your classpath. So this indicates, that this is not a plugin issue.

Usually you don't have to setup the classpath, Ant does that for you. Please also read Creating an Ant build script.

Please try a snippet like this one:

node {
    try {
        checkout scm
        stage('Build') {
            sh '''
                dir=$(pwd)
                curl [your-dita-ot-url] --output dita-ot.zip
                unzip -qq "$dir/dita-ot.zip"
                rm dita-ot.zip
                chmod +x ${WORKSPACE}/dita-ot/bin/ant
                ${WORKSPACE}/dita-ot/bin/ant -f ${WORKSPACE}/build.xml -Ddita.dir=$dir/dita-ot -Dbranch.name=$BRANCH_NAME
            '''
        }
    } catch (e) {
        currentBuild.result = "FAILED"
        throw e
    } finally {
        notifyBuild(currentBuild.result)
    }
}