简体   繁体   English

Maven:使用其 ftp 地址在本地存储库中安装一个 jar

[英]Maven: Install in local repository a jar using its ftp address

I have my maven local repository located on a Windows machine and I am trying to install a jar in this repository using the ftp address of the jar(jar is located on a linux machine) using eclipse.我的 maven 本地存储库位于 Windows 机器上,我正在尝试使用 Eclipse 使用 jar 的 ftp 地址(jar 位于 linux 机器上)在此存储库中安装一个 jar。 Here are my settings.xml and pom.xml这是我的settings.xmlpom.xml

settings.xml设置.xml

   <server>
    <id>{server_address}</id>
    <username>username</username>
    <password>password</password>
    <configuration>
        <endpointChecking>false</endpointChecking>
    </configuration>
  </server>

pom.xml pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maven.bcone</groupId>
<artifactId>ArtifactName</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Sample</name>
<properties>
    <ics.version>17.4.5</ics.version>
    <ftp.dir>//sftp://username@{server_address}</ftp.dir>
</properties>

<dependencies>
    <dependency>
        <groupId>com.oracle.ics</groupId>
        <artifactId>cpi_omcs.jar</artifactId>
        <version>${ics.version}</version>
    </dependency>

</dependencies>
<build>
    <finalName>BuildName</finalName>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.2</version>
            <executions>
                <execution>
                    <id>install-cpi_omcs</id>
                    <phase>clean</phase>
                    <configuration>
                        <file>${ftp.dir}/home/steve/myJars/cpi_omcs.jar</file>
                        <groupId>com.oracle.ics</groupId>
                        <artifactId>cpi_omcs</artifactId>
                        <version>${ics.version}</version>
                        <packaging>jar</packaging>
                        <generatePom>true</generatePom>
                    </configuration>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
    <repositories>
        <repository>
            <id>{server_address}</id>
            <name>158_bcone</name>
            <url>sftp://username@{server_address}</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
        </repository>
    </repositories>
  </project>

After running mvn:clean, I get below error运行 mvn:clean 后,出现以下错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file (install-cpi_omcs) on project BconeAdapter: The specified file '\\\\sftp:\\username@{server_addres}\\home\\steve\\myJars\\cpi_omcs.jar' not exists -> [Help 1] [错误] 无法在项目 BconeAdapter 上执行目标 org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file (install-cpi_omcs): 指定的文件 '\\\\sftp:\\username@{server_addres }\\home\\steve\\myJars\\cpi_omcs.jar' 不存在 -> [帮助 1]

The jar file exists at the mentioned location but maven is not able to find it. jar 文件存在于上述位置,但 maven 无法找到它。 What am I missing here?我在这里缺少什么?

I was able to do this using these maven plugins我能够使用这些 Maven 插件来做到这一点

<properties>
    <ics.version>18.1.3</ics.version>
    <temp.dir>./temp/</temp.dir>
    <ftp.dir>scp://username:password@server-address</ftp.dir>
    <ics.dir>/u01/app/oracle/lib</ics.dir>
</properties>

    <build>
    <finalName>MyProject</finalName>
    <plugins>

        <!-- DOWNLOAD THE JAR FILES TO A TEMP FOLDER ON THE LOCAL MACHINE -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>wagon-maven-plugin</artifactId>
            <version>1.0</version>

            <executions>
                <execution>
                    <id>download-ftp-suite</id>
                    <configuration>
                        <url>${ftp.dir}:${ics.dir}</url>
                        <toDir>${temp.dir}</toDir>
                        <includes>
                            */**/*.jar
                        </includes>
                    </configuration>
                    <goals>
                        <goal>download</goal>
                    </goals>
                </execution>
              </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.2</version>
            <executions>

                <execution>
                    <id>install-one-of-the-downloaded-jars</id>
                    <phase>site</phase>
                    <configuration>
                        <file>${temp.dir}one-of-the-downloaded-jars.jar</file>
                        <groupId>com.oracle.ics</groupId>
                        <artifactId>one-of-the-downloaded-jars</artifactId>
                        <version>${ics.version}</version>
                        <packaging>jar</packaging>
                        <generatePom>true</generatePom>
                    </configuration>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                </execution>
               </executions>
        </plugin>
     </plugins>


    <extensions>
        <!-- Enabling the use of SSH IN ACCESSING FTP/SCP -->
        <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-ssh</artifactId>
            <version>3.0.0</version>
        </extension>
    </extensions>
</build>

With these changes there is no need to add server details in settings.xml通过这些更改,无需在 settings.xml 中添加服务器详细信息

Maybe you should be using maven-wagon .也许你应该使用maven-wagon I am not sure if maven-install-plugin can handle network paths.我不确定maven-install-plugin可以处理网络路径。

The rest is total copy&paste from Apaches page as it is the minimun essential information needed to get the solution working其余部分是从 Apaches 页面完全复制和粘贴,因为它是使解决方案工作所需的最少必要信息

From Apache maven deploy plugin page来自Apache maven 部署插件页面

In order to deploy artifacts using FTP you must first specify the use of an FTP server in the distributionManagement element of your POM as well as specifying an extension in your build element which will pull in the FTP artifacts required to deploy with FTP:为了使用 FTP 部署工件,您必须首先在 POM 的 distributionManagement 元素中指定 FTP 服务器的使用,并在构建元素中指定一个扩展,它将拉入使用 FTP 部署所需的 FTP 工件:

<distributionManagement>
   <repository>
     <id>ftp-repository</id>
     <url>ftp://repository.mycompany.com/repository</url>
   </repository>
</distributionManagement>

<build>
   <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-ftp</artifactId>
         <version>*version*</version>
      </extension>
   </extensions>
</build>

Your settings.xml would contain a server element where the id of that element matches id of the FTP repository specified in the POM above:您的 settings.xml 将包含一个 server 元素,其中该元素的 id 与上面 POM 中指定的 FTP 存储库的 id 匹配:

<settings>
   ...
   <servers>
      <server>
         <id>ftp-repository</id>
         <username>user</username>
         <password>pass</password>
      </server>
  </servers>
  ...
</settings>

You should, of course, make sure that you can login into the specified FTP server by hand before attempting the deployment with Maven.当然,在尝试使用 Maven 进行部署之前,您应该确保可以手动登录到指定的 FTP 服务器。 Once you have verified that everything is setup correctly you can now deploy your artifacts using Maven:确认一切设置正确后,您现在可以使用 Maven 部署您的工件:

mvn deploy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在本地Maven存储库中安装多个jar文件 - install multiple jar files in local maven repository maven clean install不从本地存储库中获取jar - maven clean install not taking jar from local repository 将Jar依赖项安装到本地存储库作为Maven构建过程的一部分 - Install Jar Dependency to Local Repository as Part of Maven Build Process 使用Maven安装本地jar - Install local jar with maven Maven-Maven-war-plugin生成jar并将其安装到maven本地存储库 - Maven - maven-war-plugin to generate jar and install it to maven local repository 如何将 Gradle jar 编译的安装到本地 Gradle Repository files-2.1 而不是 Maven 存储库中? - How to install a compiled by Gradle jar into the local Gradle Repository files-2.1 instead of the Maven repository? Maven 不使用本地存储库 - Maven not using local repository 在 maven 解决其依赖关系之前,在本地 maven 中安装第三方 jar? - Install third party jar in local maven before maven resolves its dependency? Maven Shade 插件:“mvn install”如何在本地存储库中包含通过“mvn package”生成的相同 jar? - Maven Shade Plugin: how 'mvn install' can include in the local repository the same jar generated through 'mvn package'? 将罐子从Maven存储库下载到本地目录 - download a jar from maven repository to a local directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM