Gibt es eine ant-Task (ähnlich FTP- oder scp-Tasks), die es mir erlauben würde, eine Reihe von Dateien in eine Windows-Freigabe (smb) zu kopieren?Ant-Task zum Kopieren nach Windows-Freigabe (SMB)
Edit: Ich musste eine Aufgabe mit jcifs dafür erstellen. Wenn jemand es braucht, hier ist der Code.
Hängt von jcifs und apache ioutils ab.
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 versuche deine Aufgabe zu benutzen. Ich kompilierte es und exportierte es von Eclipse (einschließlich aller abhängigen Objekte) aber Ant läuft in Schwierigkeiten und ich bekomme eine java.lang.NoClassDefFoundError: jcifs/smb/SmbFile) - Ich nehme an, ich vermisse nur etwas Einfaches. Irgendwelche Tipps/Ideen? –