英文:
How to invoke a JAR resides in the maven local repository?
问题
作为CI/CD流程的一部分,我正在从Maven仓库(Sonatype Nexus)中获取一个JAR文件。
现在,我想要简单地运行“java -jar”命令。
最简单的方法是什么?
我只需要使用命令java -jar ${MAVEN_HOME}/repository/com/company/path/to/my/x.jar吗?
还是有更简单的方法?
英文:
As part of a CI/CD process, I'm pulling a JAR from a maven repository (Sonatype nexus)
Now, I'd like to simply "java -jar" it.
What is the simplest way to do it?
Should I just use the command java -jar ${MAVEN_HOME}/repository/com/company/path/to/my/x.jar?
Or is there a simpler way?
答案1
得分: 1
你可以创建一个sh文件,并将以下内容添加到文件中以下载jar包:
wget --user USERNAME --password PASSWORD 上传jar包的Nexus URL
java -Djava.security.egd=file:/dev/./urandom -jar jar包的名称.jar
exec "$@"
> 下一步将帮助你将jar包下载到另一个项目中
在你的pom.xml中,你需要添加repository标签:
<repositories>
    <repository>
        <id>remote</id>
        <url>托管jar包的URL</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> <!-- 用户名 -->
      <password>****</password> <!-- 密码 -->
    </server>
  </servers>
</settings>
之后,在你的pom.xml中添加依赖项,它将会下载jar包到本地的m2文件夹:
<dependency>
    <groupId>项目的groupId</groupId> 
    <artifactId>项目的artifactId</artifactId> <!-- jar包的artifactId -->
    <version>项目的版本号</version>
</dependency>
在创建jar包时,你需要添加这些groupId、artifactId和version信息。
英文:
You can create a sh file and this to download 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 "$@"
> The Next step will help you to download jar to another project
In your pom.xml you need to add repository tag
<repositories>
    <repository>
       <id>remote</id>
       <url>Url where you have hosted the jar</url>
     </repository>
</repositories>
Also, you need to add setting.xml if your remote is password protected
<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>
After that add dependency in your pom.xml, it will download the jar to you local m2 folder
<dependency>
			<groupId>group id of project</groupId> 
			<artifactId>artifact of project</artifactId>    //artifact of your jar
			<version>version of your project</version>
		</dependency>
This groupId, artifactId and version that you need to add when you will create the jar
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论