Ant-Task zum Kopieren Auf einen Windows-Share (SMB)

Gibt es einen ant-task (ähnlich ftp-oder scp-Aufgaben), die mir erlauben, zu kopieren, einen Satz von Dateien für eine windows - (smb -) Freigabe?

Edit: ich hatte um eine Aufgabe zu erstellen mit jcifs für diese. Wenn jemand braucht, hier der code.

Hängt davon ab, jcifs und apache ioutils.

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import jcifs.smb.SmbFile;

import org.apache.commons.io.IOUtils;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Copy;

public class SmbCopyTask extends Task
{
   private File src;
   private String tgt;

   public void execute() throws BuildException
   {
      try
      {
         recursiveCopy(src);
      }
      catch (Exception e)
      {
         throw new BuildException(e);
      }
   }

   public void recursiveCopy(File fileToCopy) throws IOException
   {

      String relativePath = src.toURI().relativize(fileToCopy.toURI()).getPath();
      SmbFile smbFile = new SmbFile(tgt, relativePath);
      if(!smbFile.exists()) 
      {
         smbFile.createNewFile();
      }
      if(!fileToCopy.isDirectory()) 
      {
         System.out.println(String.format("copying %s to %s", new Object[]{fileToCopy, smbFile}));
         IOUtils.copy(new FileInputStream(fileToCopy), smbFile.getOutputStream());
      }
      else
      {
         File[] files = fileToCopy.listFiles();
         for (int i = 0; i < files.length; i++)
         {
            recursiveCopy(files[i]);
         }
      }
   }

   public void setTgt(String tgt)
   {
      this.tgt = tgt;
   }

   public String getTgt()
   {
      return tgt;
   }

   public void setSrc(File src)
   {
      this.src = src;
   }

   public File getSrc()
   {
      return src;
   }
}
  • Hoffentlich werden Sie dies sehen. Ich bin versucht, Ihre Aufgabe. Ich habe es kompiliert und exportiert es aus eclipse (mit allen abhängigen Objekten) allerdings Ameise läuft in Schwierigkeiten und ich bekomme eine java.lang.NoClassDefFoundError: jcifs-smb - /SmbFile) - ich nehme an, ich bin nur etwas fehlt einfach. Irgendwelche Tipps/Ideen?
InformationsquelleAutor SamBeran | 2010-01-13
Schreibe einen Kommentar