java 如何在 Jenkins 的类路径中使用一组 jar 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13508958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 13:02:32  来源:igfitidea点击:

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

javajenkinsbuild-automation

提问by Harshavardhan Konakanchi

How to make this possible ?

如何使这成为可能?

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

我有一组要包含在 CLASSPATH 变量中的 jar 文件。

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

我不想将命令SET CLASSPATH=xxx.jar;xx.jar;..作为构建步骤的一部分。

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

我不想手动设置环境变量 CLASSPATH 作为系统属性的一部分。

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

我尝试将一组 jar 文件复制到Jenkins_HOME/war/WEB-INF/lib并启动了 Jenkins 服务器。但不能让它成为可能......任何解决方案?

回答by Anees Ahmed Mohammed

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

您可以尝试通过附加的类路径元素 maven。您可以在以下链接中查看详细信息 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>

回答by Harshavardhan Konakanchi

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

如下设置 CLASSPATH 环境,任何 jar 文件都会更新它的特定目录

SET CLASSPATH=<your_lib_directory>\*

设置类路径=<your_lib_directory>\*

This will pick up all the updated JAR files

这将选取所有更新的 JAR 文件

回答by Anders R. Bystrup

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 Mavenand 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.

我的建议是您考虑使用Maven进行构建并将您的 Jenkins 作业转换为 Maven 作业 - 然后您可以在 POM 中而不是在 Jenkins 中处理您的额外依赖项 - 这可能更优雅一些。

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

例如,您的 JUnit 和 Selenium 依赖项可以包含为

<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.

<scope>将它们排除在最终工件之外很重要)并且在 Jenkins 作业配置中,“目标和选项”可能是test package.

Hope that helps.

希望有帮助。

Cheers,

干杯,