我通过使用SVNkit API for Java在ssh上尝试了远程SVN。首先,我想重新做一个例子 在http://wiki.svnkit.com/Printing_Out_A_Subversion_Repository_Tree打印出Subversion存储库树 当我试图将URL从http类型替换为ssh类型时,我收到了错误。请帮我配置SVNkit中的ssh。 这是我的http代码(工作得很好):
public class SVNconnect {
private static long latestRevision;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
DAVRepositoryFactory.setup();
String url = "http://svn.svnkit.com/repos/svnkit/trunk";
String name = "anonymous";
String password = "anonymous";
SVNRepository repository = null;
try {
repository = SVNRepositoryFactory.create( SVNURL.parseURIDecoded( url ) );
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name , password );
repository.setAuthenticationManager( authManager );
System.out.println( "Repository Root: " + repository.getRepositoryRoot( true ) );
System.out.println( "Repository UUID: " + repository.getRepositoryUUID( true ) );
SVNNodeKind nodeKind = repository.checkPath( "" , -1 );
if ( nodeKind == SVNNodeKind.NONE ) {
System.err.println( "There is no entry at '" + url + "'." );
System.exit( 1 );
}
else if ( nodeKind == SVNNodeKind.FILE ) {
System.err.println( "The entry at '" + url + "' is a file while a directory was expected." );
System.exit( 1 );
}
listEntries( repository , "" );
latestRevision = repository.getLatestRevision( );
System.out.println( "Repository latest revision: " + latestRevision );
}
catch (SVNException svne) {
System.out.println("ERROR:" +svne);
}
}
public static void listEntries( SVNRepository repository, String path ) throws SVNException {
Collection entries = repository.getDir( path, -1 , null , (Collection) null );
Iterator iterator = entries.iterator( );
while ( iterator.hasNext( ) ) {
SVNDirEntry entry = ( SVNDirEntry ) iterator.next( );
System.out.println( "/" + (path.equals( "" ) ? "" : path + "/" ) + entry.getName( ) +
" ( author: '" + entry.getAuthor( ) + "'; revision: " + entry.getRevision( ) +
"; date: " + entry.getDate( ) + ")" );
if ( entry.getKind() == SVNNodeKind.DIR ) {
listEntries( repository, ( path.equals( "" ) ) ? entry.getName( ) : path + "/" + entry.getName( ) );
}
}
}
}
以下是我尝试使用ssh的代码:
public class SVNconnect {
private static long latestRevision;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
SVNconnect t=new SVNconnect();
try{
t.go();
} catch(Exception ex){
ex.printStackTrace();
}
//DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
String url = "svn+ssh://quan@192.168.1.128/data/svnrepo/QualityAssurance/trunk/Training/Quan";
String name = "quan";
String password = "quan@dolphin";
SVNRepository repository = null;
try {
repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) );
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name , password );
repository.setAuthenticationManager( authManager );
System.out.println( "Repository Root: " + repository.getRepositoryRoot( true ) );
System.out.println( "Repository UUID: " + repository.getRepositoryUUID( true ) );
SVNNodeKind nodeKind = repository.checkPath( "" , -1 );
if ( nodeKind == SVNNodeKind.NONE ) {
System.err.println( "There is no entry at '" + url + "'." );
System.exit( 1 );
}
else if ( nodeKind == SVNNodeKind.FILE ) {
System.err.println( "The entry at '" + url + "' is a file while a directory was expected." );
System.exit( 1 );
}
listEntries( repository , "" );
latestRevision = repository.getLatestRevision( );
System.out.println( "Repository latest revision: " + latestRevision );
}
catch (SVNException svne) {
System.out.println("ERROR:" +svne);
}
}
public static void listEntries( SVNRepository repository, String path ) throws SVNException {
Collection entries = repository.getDir( path, -1 , null , (Collection) null );
Iterator iterator = entries.iterator( );
while ( iterator.hasNext( ) ) {
SVNDirEntry entry = ( SVNDirEntry ) iterator.next( );
System.out.println( "/" + (path.equals( "" ) ? "" : path + "/" ) + entry.getName( ) +
" ( author: '" + entry.getAuthor( ) + "'; revision: " + entry.getRevision( ) +
"; date: " + entry.getDate( ) + ")" );
if ( entry.getKind() == SVNNodeKind.DIR ) {
listEntries( repository, ( path.equals( "" ) ) ? entry.getName( ) : path + "/" + entry.getName( ) );
}
}
}
public void go() throws Exception{
String host="xxx.xxx.xxx.xxx";
String user="quan";
String password="**********";
int port=22;
int tunnelLocalPort=3306;
String tunnelRemoteHost="127.0.0.1";
int tunnelRemotePort=3306;
JSch jsch=new JSch();
Session session=jsch.getSession(user, host, port);
session.setPassword(password);
localUserInfo lui=new localUserInfo();
session.setUserInfo(lui);
session.connect();
session.setPortForwardingL(tunnelLocalPort,tunnelRemoteHost,tunnelRemotePort);
System.out.println("Connected");
Channel channel=session.openChannel("shell");
channel.connect();
}
}
class localUserInfo implements UserInfo{
String passwd;
public String getPassword(){ return passwd; }
public boolean promptYesNo(String str){return true;}
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){return true; }
public boolean promptPassword(String message){return true;}
public void showMessage(String message){}
}
然后我收到了错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.tmatesoft.svn.core.internal.io.svn.ISVNConnectorFactory$1.createConnector(ISVNConnectorFactory.java:33)
at org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryImpl.openConnection(SVNRepositoryImpl.java:1250)
at org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryImpl.testConnection(SVNRepositoryImpl.java:96)
at org.tmatesoft.svn.core.io.SVNRepository.getRepositoryRoot(SVNRepository.java:323)
at svnconnect.SVNconnect.main(SVNconnect.java:53)
Caused by: java.lang.RuntimeException: Uncompilable source code - package com.trilead.ssh2 does not exist
at org.tmatesoft.svn.core.internal.io.svn.SVNSSHConnector.<clinit>(SVNSSHConnector.java:14)
... 5 more