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

标签 java eclipse maven ftp

我的 maven 本地存储库位于 Windows 计算机上,我尝试使用 eclipse 使用 jar 的 ftp 地址(jar 位于 Linux 计算机上)在此存储库中安装 jar。这是我的 settings.xmlpom.xml

settings.xml

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

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>

运行 mvn:clean 后,出现以下错误

[错误] 无法在项目 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]

jar 文件存在于上述位置,但 Maven 无法找到它。我在这里缺少什么?

最佳答案

我能够使用这些 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>

通过这些更改,无需在 settings.xml 中添加服务器详细信息

关于java - Maven:使用其 ftp 地址在本地存储库中安装 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47750491/

相关文章:

java - 可以将父属性设置为最终属性,以使其不能被子属性覆盖

java - 为什么我的 Maven 找不到 stripe 库?

java - 使用 Eclipse 在 Tomcat 上进行奇怪的部署

java - 将 Collection<List<T>> 转换为二维数组 T[][]

java - 为什么 Eclipse 2018-12 会询问是否创建模块的问题?

java - 通过 Java 使用 Selenium Webdriver 缺少 size() 选项

java - 无法升级 eclipse 或 Android ADK 并且找不到 java.exe...hunh?

javafx - 对话框关闭时取消任务

java - Java 中的简单线程行为

java - 如何初始化自定义类对象的二维列表 - Java