Page tree
Skip to end of metadata
Go to start of metadata

Commons VFS Example Shell

This page shows some examples to configure the classpath and use the VFS Example Shell.

All examples expect to be started from within the Apache Commons VFS source directory (refering to build artifacts as well as external dependencies in a local maven repository). Linux/Unix commands are marked with {{$ }} prompt, for sample Windows command you see a {{C:vfs> }} prompt. Commands entered into the VFS Example Shell are marked with the {{> }} prompt.

Enabling the SMB provider from the sandbox:

$ REP=~/.m2/repository
$ LIBS=$REP/commons-logging/commons-logging/1.2/commons-logging-1.2.jar
$ LIBS=$LIBS:$REP/jcifs/jcifs/0.8.3/jcifs-0.8.3.jar
$ LIBS=$LIBS:core/target/commons-vfs2-2.1.jar:examples/target/commons-vfs2-examples-2.1.jar:sandbox/target/commons-VFS2-sandbox-2.1.jar
$ java -cp $LIBS org.apache.commons.vfs2.example.Shell
VFS Shell 2.1
> info
Info about default manager "org.apache.commons.vfs2.impl.StandardFileSystemManager":
  Provider Schemes: [res, ram, file, tmp, smb]
   Virtual Schemes: [gz, zip, war, par, ear, jar, sar, ejb3]
> ls smb://Domain\User:PASSWORD@host/Users/
Administrator/
All Users/
User/
desktop.ini

Using the ftp(s) provider:

C:vfs> set REP=\Users\USERNAME\.m2\repository
C:vfs> set LIBS=%REP%\commons-logging\commons-logging\1.2\commons-logging-1.2.jar
C:vfs> set LIBS=%LIBS%;%REP%\commons-net\commons-net\2.2\commons-net-2.2.jar
C:vfs> set LIBS=%LIBS%;core\target\commons-vfs2-2.1.jar;examples/target/commons-vfs2-examples-2.1.jar
C:vfs> java -cp $LIBS org.apache.commons.vfs2.example.Shell
VFS Shell 2.1
> info
Info about default manager "org.apache.commons.vfs2.impl.StandardFileSystemManager":
  Provider Schemes: [res, ram, ftps, file, ftp, tmp]
   Virtual Schemes: [gz, zip, war, par, ear, jar, sar, ejb3]
> ls ftp://ftp.fau.de/apache/commons/vfs/
Contents of ftp://ftp.fau.de/apache/commons/vfs
HEADER.html
README.html
RELEASE_NOTES.txt
binaries/
source/

Loading resources from the classpath:

VFS Shell 2.1
> ls -R res:META-INF/maven/
Contents of jar:file:///C:/ws/asf/commons-vfs2-project/core/target/commons-vfs2-2.1-SNAPSHOT.jar!/META-INF/maven
org.apache.commons/
    commons-vfs2/
        pom.properties
        pom.xml
> cat res:META-INF/maven/org.apache.commons/commons-vfs2/pom.properties
#Generated by Maven
#Fri Jan 09 02:48:03 CET 2015
version=2.1-SNAPSHOT
groupId=org.apache.commons
artifactId=commons-vfs2

For http(s) (and more general URIs):

C:vfs> set LIBS=%REP%\commons-logging\commons-logging\1.2\commons-logging-1.2.jar
C:vfs> set LIBS=%LIBS%;%REP%\org\apache\commons\httpclient;%REP%\commons-httpclient\commons-httpclient\3.1\commons-httpclient-3.1.jar
C:vfs> set LIBS=%LIBS%;%REP%\commons-codec\commons-codec\1.2\commons-codec-1.2.jar
C:vfs> set LIBS=%LIBS%;core\target\commons-vfs2-2.1.jar;examples/target/commons-vfs2-examples-2.1.jar
C:vfs> java -cp $LIBS org.apache.commons.vfs2.example.Shell
VFS Shell 2.1
> cat https://www.apache.org/robots.txt
User-agent: *
Disallow: /websrc
Crawl-Delay: 4

The following example describes how to set up a file in HDFS and how to access it with the VFS Example Shell:

$ HADOOP_HOME=/home/user/hadoop-2.6.0 
$ HADOOP_CLASSPATH=`$HADOOP_HOME/bin/hadoop classpath` 
$ $HADOOP_HOME/bin/hadoop fs -mkdir /vfs-test 
$ $HADOOP_HOME/bin/hadoop fs -copyFromLocal /tmp/test.txt /vfs-test/text.txt 
$ $HADOOP_HOME/bin/hadoop fs -ls -R / 
drwxr-xr-x - user supergroup  0 2015-01-09 21:56 /vfs-test 
-rw-r--r-- 3 user supergroup 15 2015-01-09 21:56 /vfs-test/text.txt 

$ REP=~/.m2/repository 
$ LIBS=$REP/commons-logging/commons-logging/1.2/commons-logging-1.2.jar 
$ LIBS=$LIBS:core/target/commons-vfs2-2.1-SNAPSHOT.jar:examples/target/commons-vfs2-examples-2.1-SNAPSHOT.jar
$ java -cp $LIBS:$HADOOP_CLASSPATH org.apache.commons.vfs2.example.Shell 
15/01/09 22:01:44 INFO impl.StandardFileSystemManager: Using "/tmp/vfs_cache" as temporary files store. 
VFS Shell 2.1-SNAPSHOT 
> info   
Default manager: "org.apache.commons.vfs2.impl.StandardFileSystemManager" version 2.1-SNAPSHOT 
Provider Schemes: [https, res, gz, hdfs, sftp, ftps, ram, http, file, ftp, tmp, bz2] 
Virtual Schemes: [zip, war, par, ear, jar, sar, ejb3, tar, tbz2, tgz] 
> info hdfs   
Provider Info for scheme "hdfs": 
capabilities: [GET_TYPE, READ_CONTENT, URI, GET_LAST_MODIFIED, ATTRIBUTES, RANDOM_ACCESS_READ, DIRECTORY_READ_CONTENT, LIST_CHILDREN] 
> ls hdfs://server:8020/vfs-test/   
15/01/09 22:02:06 INFO Configuration.deprecation: fs.default.name is deprecated. Instead, use fs.defaultFS 
15/01/09 22:02:06 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 
Contents of hdfs://server:8020/vfs-test 
text.txt 
> cat hdfs://server:8020/vfs-test/text.txt
This is a test 
  • No labels