JavaEclipseMaven(和ant)通过ssh复制jar文件的问题

JavaEclipseMaven(和ant)通过ssh复制jar文件的问题,java,ssh,maven-3,eclipse-indigo,maven-antrun-plugin,Java,Ssh,Maven 3,Eclipse Indigo,Maven Antrun Plugin,我有以下资料: 在CentOS 6.2中运行EclipseIndigo 我还在我的系统中安装了apache-ant-1.8.4,并在eclipse中将ant\u HOME变量设置为它 在eclipse中,我安装了maven2插件,该插件使用安装在我的系统上的maven-3.0.4版本(我配置了eclipse来使用它) 我在eclipse上有一个maven项目,我希望每次安装时(目标是),都能通过ssh将生成的jar文件复制到服务器上的特定位置。为此,我在我的pom.xml上执行了以下操作:

我有以下资料:

  • CentOS 6.2
    中运行
    EclipseIndigo
  • 我还在我的系统中安装了
    apache-ant-1.8.4
    ,并在
    eclipse
    中将
    ant\u HOME
    变量设置为它
  • 在eclipse中,我安装了
    maven2
    插件,该插件使用安装在我的系统上的
    maven-3.0.4
    版本(我配置了
    eclipse
    来使用它)
我在eclipse上有一个maven项目,我希望每次安装时(目标是),都能通过ssh将生成的jar文件复制到服务器上的特定位置。为此,我在我的
pom.xml
上执行了以下操作:



   <build>
    <plugins >
            <plugin>
        <groupId > org.apache.maven.plugins </groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>install</phase>
                    <configuration>
                        <tasks name="ssh_task">
                            <taskdef name="scp" 
                                      classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" classpathref="/usr/local/apache-ant/apache-ant-1.8.4/lib/ant-jsch.jar" />
                            <scp file="/absolute/path/to/myfile.jar" 
                                 todir="root@$10.3.1.1:/remote/location" 
                                 password="mypass" 
                                 trusted="true"/>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>


Maven的安装阶段旨在将工件安装到本地存储库中,而不是将文件传输到远程服务器。如果您正试图将和工件部署到Tomcat/JBoss中,那么最好查看打算将工件部署到服务器的或


此外,我建议将工件上传到服务器,而不是使用Ant,这样会使工作更轻松。

classpathref
用于定义对先前定义的属性的引用

您应该尝试定义classpath变量:

<path id="jsch-classpath">
        <fileset dir="/usr/local/apache-ant/apache-ant-1.8.4/lib/" includes="ant-jsch.jar"/>
</path>

然后在任务中使用它:

<taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" classpathref="jsch-classpath" />


谢谢,你能提供ant-diagnostics的输出吗。@Hovanesyan:你能帮我弄到这个吗?我对
ant
非常陌生。如果正确配置了ant(在$PATH和all中),您应该能够在终端/控制台中执行命令“ant-diagnostics”。你是如何安装Ant的?从发行包还是从zip存档?@hovanesyan从zip存档。为此,我一步一步地遵循Ant用户指南。|我将输出放在答案上。jsch实际上在java类路径中……我不想部署工件。我只想做我建议的事情:将我的jar复制到服务器上的某个位置,运行中的应用程序将能够在运行时加载该jar。最简单的方法是声明
includes=“*.jar”
,但如果需要定义更精确的场景,请查看。
<taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" classpathref="jsch-classpath" />