How to use a set of jar files in classpath in Jenk

2020-08-01 07:42发布

问题:

How to make this possible ?

I had a set of jar files which are to be included to CLASSPATH variable.

I don't want to give the command SET CLASSPATH=xxx.jar;xx.jar;.. as part of the build step.

I dont' want to manually set the Environment variable CLASSPATH as part of system properties.

I tried by copying a set of jar files into Jenkins_HOME/war/WEB-INF/lib and had started the Jenkins server. But couldn't make it possible... Any Solution ?

回答1:

You can try by additional class-path elements maven. you can see the details in below link https://maven.apache.org/surefire/maven-surefire-plugin/examples/configuring-classpath.html

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
    <configuration>
      <additionalClasspathElements>
        <additionalClasspathElement>path/to/additional/resources</additionalClasspathElement>
        <additionalClasspathElement>path/to/additional/jar</additionalClasspathElement>
        <additionalClasspathElement>path/to/csv/jar1, path/to/csv/jar2</additionalClasspathElement>
      </additionalClasspathElements>
    </configuration>
  </plugin>
</plugins>



回答2:

Set CLASSPATH environment as follows and any jar file updated it particular directory

SET CLASSPATH=<your_lib_directory>\*

This will pick up all the updated JAR files



回答3:

I think you are making things harder on yourself than needs be. Why don't you want to set the classpath as a pre-build step? Perhaps because the artifacts change regularly?

My suggestion is that you look into building with Maven and convert your Jenkins job to a Maven job - then you can handle your extra dependencies in the POM and not in Jenkins - which may be a little more elegant.

For example, your JUnit and Selenium dependencies could be included as

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.9</version>
        <scope>test</scope>
    </dependency>
    ... etc

(the <scope> being important to keep them out of your final artifact) and in the Jenkins job configuration, "Goals and options" could be test package.

Hope that helps.

Cheers,