ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antoine Lévy-Lambert <anto...@antbuild.com>
Subject Re: Ant Api usage problems
Date Wed, 25 Feb 2004 21:09:23 GMT
Try to set a dir for your fileset.
The dir of the fileset will be the location where the filese you are 
going to retrieve will be located.
Also, which external libs do you use ? The ant 1.6 ftp task requires 
jakarta-oro and commons-net.
If your ftp server is a Microsoft ftp server, then  you need the head 
revision of commons-net, because the parser
has been improved there.
Also you can try to create a Logger, register it with your Project, and 
set the Logger to listen for debug level events, then
you might find out more about what is going on.

Also, try to run your ftp using plain ant (writing a small build file), 
with of course the same commons-net and jakarta-oro as
in the API case. If it works using plain ant and not in the API case 
then come back to us.
If it does not work using plain ant also come back to the list, with the 
output of ant -verbose.

Cheers,
Antoine

Hugo Costa wrote:

>Hi!
>
>Thank you, for your help.
>I got it to work partially...
>
>My code is now this:
>
>------------------------ FtpTest.java -------------------------------
>
>import org.apache.tools.ant.Project;
>import org.apache.tools.ant.types.FileSet;
>import org.apache.tools.ant.taskdefs.optional.net.FTP;
>import org.apache.tools.ant.taskdefs.optional.net.FTP.Action;
>import java.io.*;
>
>public class FtpTest {
>
>	public static void main(String[] args){
>		
>		Project project = new Project();
>		project.init();
>		FileSet fileset = new FileSet();
>		//fileset.setDir(new File(resourcesSrc));
>		fileset.setIncludes(args[4]);
>		
>		FTP.Action ftpa = new FTP.Action();
>		ftpa.setValue("get");
>		FTP ftp=new FTP();
>		ftp.setProject(project);
>		ftp.setServer(args[0]);
>		ftp.setUserid(args[1]);
>		ftp.setPassword(args[2]);
>		ftp.setRemotedir(args[3]);
>		ftp.addFileset(fileset);
>		ftp.setVerbose(true);
>		ftp.setAction(ftpa);
>		ftp.execute();
>		
>	}	
>}
>
>----------------------------------------------------------------
>
>But now it just hangs, it runs and stays there doing nada...
>I can see in my linux logs that there is a connection to localhost.
>
>This is during the execute method, I must have something wrong.
>Can this be so hard to do? 
>
>Do I have to use FTPClient class in conjunction to make this work?
>
>Thank you.  
>
>-----Original Message-----
>From: Antoine Lévy-Lambert [mailto:antoine@antbuild.com] 
>Sent: terça-feira, 24 de Fevereiro de 2004 21:39
>To: Ant Users List
>Subject: Re: Ant Api usage problems
>
>Hugo Costa wrote:
>
>  
>
>>Hi,
>>
>>I'm having problems using some optional tasks of the Ant Api.
>>The error is always the same, so i must be doing something wrong.
>>I'm starting in java as well, as you can see...
>>
>>On example of what i'm doing is this, just trying to login to my own
>>ftp. I'm on linux. I've tried with Scp and the result is the same.
>>
>>This builds correctly with ant.
>>The error is always: java.lang.NullPointerException
>>
>>I've done another simple example of just making a directory and
>>unzipping some files there with others ant task (Expand and mkDir),
>>passing the name of the filezip and the name of the directory.
>>
>>So i don't understand what's wrong.
>>
>>I have the jars needed for both scp and ftp, i can use this tasks within
>>a build.xml with no problems.
>> 
>>
>>    
>>
>I guess you get hit when ant tries to log.
>do ftp.setProject(project);
>before you start the execution, it should be better.
>Also, I do not know why you make your class extend FTP, using it is good 
>enough.
>
>Antoine
>
>here an example of ant api usage based on an existing build.xml file
>
>public class testcvsversion {
>    public static void main (String [] argv){
>        Diagnostics.validateVersion();
>        String filename="/dev/testant/cvsversion.xml";
>        StringBuffer logBuffer;
>        StringBuffer fullLogBuffer;
>        Project project=new Project();
>        logBuffer = new StringBuffer();
>        fullLogBuffer = new StringBuffer();
>        project = new Project();
>        project.init();
>        project.setUserProperty( "ant.file" , new 
>File(filename).getAbsolutePath() );
>        ProjectHelper.configureProject(project, new File(filename));
>        project.addBuildListener(createLogger());
>    }
>    private static BuildLogger createLogger() {
>        BuildLogger logger = null;
>        logger = new DefaultLogger();
>        logger.setMessageOutputLevel(Project.MSG_INFO);
>        logger.setOutputPrintStream(System.out);
>        logger.setErrorPrintStream(System.err);
>        logger.setEmacsMode(false);
>
>        return logger;
>    }
>
>
>  
>
>>------------- Ftp.java -------------------------
>>
>>import org.apache.tools.ant.Project;
>>import org.apache.tools.ant.Target;
>>import org.apache.tools.ant.taskdefs.optional.net.FTP;
>>import org.apache.tools.ant.BuildException;
>>import java.io.File;
>>
>>public class Ftp extends FTP{
>>
>>	public static void FtpMkDir (String ftpServer, String userId, String
>>userPassword, String remoteDir) {
>>
>>		try {
>>			Project project = new Project();
>>			
>>			project.setName("testeftp");
>>			project.init();
>>
>>			System.out.println(ftpServer);
>>			System.out.println(userId);
>>			System.out.println(userPassword);
>>			System.out.println(remoteDir);
>>			
>>			FTP ftp = new FTP();
>>			ftp.setServer(ftpServer);
>>			ftp.setUserid(userId);
>>			ftp.setPassword(userPassword);
>>                       //
>> 
>>
>>    
>>
>                                                    add here
>                                                    ftp.setProject(project);
>
>  
>
>>			System.out.println("Ponto 5");
>>			
>>			ftp.execute();
>>
>>		}
>>		catch (BuildException e) {
>>			System.out.println("FTP Error: " + e);
>>		}
>>		
>>	}
>>	
>>	
>>}
>>
>>
>>
>> 
>>
>>    
>>
>
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message