【问题标题】:How to invoke a JAR resides in the maven local repository?如何调用驻留在 Maven 本地存储库中的 JAR?
【发布时间】:2020-05-19 21:24:27
【问题描述】:

作为 CI/CD 流程的一部分,我从 maven 存储库 (Sonatype nexus) 中提取 JAR

现在,我想简单地“java -jar”它。

最简单的方法是什么?

我应该只使用命令java -jar ${MAVEN_HOME}/repository/com/company/path/to/my/x.jar吗?

或者有没有更简单的方法?

【问题讨论】:

    标签: java maven jenkins continuous-deployment


    【解决方案1】:

    你可以创建一个 sh 文件,然后这个文件来下载 jar

    wget --user USERNAME --password PASSWORD url of the nexus where the jar is uploaded
    
    java -Djava.security.egd=file:/dev/./urandom -jar name of the jar.jar
    exec "$@"
    

    下一步将帮助您将 jar 下载到另一个项目

    在你的 pom.xml 中你需要添加repository 标签

    <repositories>
        <repository>
           <id>remote</id>
           <url>Url where you have hosted the jar</url>
         </repository>
    </repositories>
    

    另外,如果您的遥控器受密码保护,您需要添加 setting.xml

    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
     <servers>
        <server>
          <id>remote</id>
          <username>***</username> //username
          <password>****</password> //password
        </server>
      </servers>
    </settings>
    

    在你的 pom.xml 中添加依赖后,它会将 jar 下载到你本地的 m2 文件夹中

    <dependency>
                <groupId>group id of project</groupId> 
                <artifactId>artifact of project</artifactId>    //artifact of your jar
                <version>version of your project</version>
            </dependency>
    

    创建 jar 时需要添加的 groupIdartifactIdversion

    【讨论】:

      猜你喜欢
      • 2021-06-10
      • 2018-05-23
      • 2016-01-22
      • 2019-05-05
      • 2021-11-21
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      相关资源
      最近更新 更多