利用java导出svn文件。

前段时间由于业务需要就写了这些代码,防止以后用得到就粘贴在这里了。

思路很简单。利用svnkit开发工具包就可以简单实现。以下为代码。

import java.io.File;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.wc.ISVNOptions;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
/**
 * svn导出工具类
 * @author Administrator
 *
 */
public class SVNCheckOut {
	@SuppressWarnings("static-access")
	public static void main(String[] args){
		            SVNCheckOut test = new SVNCheckOut();
		            test. checkOut("svn://192.168.1.235/website/docs/db/","D:/a","xiaofeng","");
		   }
	// 检出文件
	/**
	 * 
	 * @param url svn地址必须是以svn:开头的
	 * @param desPath 导出目录地址
	 * @param username svn用户名
	 * @param password svn密码
	 */
	public static void checkOut(String url,String desPath,String username,String password){
				
		        SVNClientManager ourClientManager;
		        //初始化支持svn://协议的库。 必须先执行此操作。         
		        SVNRepositoryFactoryImpl.setup();
		        //相关变量赋值
		        SVNURL repositoryURL = null;
		        try {
		            repositoryURL = SVNURL.parseURIEncoded(url);
		        } catch (SVNException e) {
		            System.out.println("初始化svn地址失败"+url);
		            System.out.println(e);
		        } 
		        FSRepositoryFactory.setup();
		        DAVRepositoryFactory.setup();
		        SVNRepositoryFactoryImpl.setup();
		        ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
		        //实例化客户端管理类
		        ourClientManager = SVNClientManager.newInstance((DefaultSVNOptions) options);//无密码
		        //ourClientManager = SVNClientManager.newInstance((DefaultSVNOptions) options,username,password);
		        //要把版本库的内容check out到的目录
		        File desFile = new File(desPath);
		        //通过客户端管理类获得updateClient类的实例。
		        SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
		        updateClient.setIgnoreExternals(false);
		        try {
		            //返回工作版本号
		            long workingVersion = updateClient.doCheckout(repositoryURL, desFile, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY,true);
		            System.out.println("把版本:"+workingVersion+" check out 到目录:"+desPath+"中");
		        } catch (SVNException e) {
		            System.out.println("检出代码出错:"+e);
		        }

		    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值