问题的Ant可选任务SSHExec和SCP。类路径的问题? [英] Problems with Ant optional tasks SSHExec and SCP. Classpath issue?

查看:216
本文介绍了问题的Ant可选任务SSHExec和SCP。类路径的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在修改Ant脚本(目前使用从内部的MyEclipse)在命令行工作的过程。我这样做是让任何人都可以检查出该项目,并构建它没有MyEclipse的。我遇到的问题是,MyEclipse的包括幕后的依赖关系。它通过查看工作区的Ant配置和整理的基础上在preferences对话框中选定库的类路径来实现的。长话短说,我需要这些依赖,使脚本足够智能,包括他们自身,没有的MyEclipse的帮助。

I'm in the process of modifying an Ant script (currently in use from within MyEclipse) to work from the command line. I'm doing this so anyone can check out the project and build it without MyEclipse. The problem I'm running into is that MyEclipse includes the dependencies behind the scenes. It does this by looking at the workspace's Ant configuration and compiling the classpath based on the selected libraries in the preferences dialog. Long story short, I need to take those dependencies and make the script smart enough to include them on its own, without the help of MyEclipse.

这是让我头疼的任务是sshexec和scp任务。他们需要一个版本jsch来运行可选的Ant任务。从我的MyEclipse的Ant classpath中删除jsch并将其添加到项目本身(LIB的/ dev)一个lib文件夹。 MyEclipse的立即抱怨说,SSHExec类找不到相关的类, com.jcraft.jsch.UserInfo 这是jsch-0.1.44.jar的一部分。

The tasks that are giving me a headache are the sshexec and scp tasks. They are optional ant tasks that require a version of jsch to run. I removed jsch from MyEclipse's Ant classpath and added it to a lib folder in the project itself (lib/dev). MyEclipse immediately complained that the SSHExec class could not find the dependent class, com.jcraft.jsch.UserInfo which is part of jsch-0.1.44.jar.

我不明白的方式,从构建脚本中设置为Ant classpath中。我有以下的code,这更增加了脚本路径元素,但我不认为蚂蚁使用这个除非明确关联到一个任务或其他元素。

I don't see a way to set the classpath for Ant from within the build script. I have the following code, which adds a path element to the script, but I don't think Ant uses this unless explicitly associated to a task or another element.

<path id="web-jars">
  <fileset dir="${web-lib}">
    <include name="**/*.jar" />
  </fileset>
  <fileset dir="${app-lib}"> <!-- this is where jsch resides --> 
    <include name="**/*.jar" />
  </fileset>
</path>

看来,我需要使用的taskdef 来定义sshexec和scp任务:

It seems that I need to use taskdef to define the sshexec and scp tasks:

<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
    classpathref="web-jars"/>

MyEclipse的抱怨这个,通过的taskdef类org.apache.tools.ant.taskdefs.optional.ssh.SSHExec需要一个类不能被找到:COM / jcraft / jsch /的UserInfo

这显然是在classpathref,网络罐子。我不能因为这个格式不正确或错误配置的taskdef在脚本中运行任何东西。

It's clearly in the classpathref, web-jars. And I can't run anything in the script because of this malformed or misconfigured taskdef.

推荐答案

这里的问题是, SSHExec 类是从它本身有没有访问的类加载器加载你的网络的罐子类加载器。提供这种类路径的taskdef不会改变这一点。每个类只能从自身的类加载器和任何父类加载器加载类,但网络的罐子类加载器是不是SSHExec的类加载器的父类加载器(它可能是周围的其他方式,因为SSHExec似乎在这里找到)。

The problem here is that the SSHExec class is loaded from a classloader which itself has no access to your web-jars class loader. Supplying this classpath for the taskdef does not change this. Each class can only load classes from its own classloader and any parent class loaders, but the web-jars classloader is not a parent class loader of SSHExec's class loader (it is likely the other way around, since SSHExec seems to be found here).

它看起来是这样的:

 ClassLoader    web-jars  ------------->   application CL ------------->  bootstrap CL

 taskdef 
       =>   look for SSHExec here
            => look first in parent class loader
                                     => look for SSHExec here
                                     => look first in parent class loader
                                                                     => look for SSHExec here
                                                                     => not found
                                     => look in our own classpath
                                     => found, load the class
                                     => it somehow uses interface UserInfo
                                     => look for UserInfo here
                                     => look first in parent class loader
                                                                    => look for UserInfo here
                                                                    => not found
                                     => look in our own classpath
                                     => not found, throw exception.

虚拟机已经在网上广口瓶类加载器不知道该找的UserInfo(及其他JSch类)。

The VM has no idea to look for UserInfo (and the other JSch classes) in the web-jars classloader.

我猜想SSHExec任务是在平时的蚂蚁类路径,即通过应用程序类加载器加载的地方。然后,从蚂蚁的类路径中移除SSHExec(或添加 jsch.jar 来的话)似乎是这里唯一的解决方案。

I suppose the SSHExec task is somewhere in the usual ant classpath, i.e. loaded by the application class loader. Then removing SSHExec from ant's classpath (or adding jsch.jar to it) seems to be the only solution here.

这篇关于问题的Ant可选任务SSHExec和SCP。类路径的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆