I think I know what your problem is, the sandbox providers are not registered automatically in 2.0. And also you need to actually use the configured authentication properties in the resolve call (see modified source below).
I typically not use the default filesystem manager but register my providers dynamically, but if you want to use the automatic detection, you need to add vfs-providers.xml to the sandbox JAR.
This is how you build a complete working JAR with 2.0:
> git clone https://github.com/apache/commons-vfs.git -b commons-vfs2-project-2.0 vfs2.0
> cd vfs2.0
> notepad sandboxpom.xml
> notepad sandboxsrc estjavaorgapachecommonsvfs2providersmb estStandaloneMain.java
> mvn -Pinclude-sandbox -DskipTests=true clean package dependency:tree
When you edit the sandbox/pom.xml, you need to make sure to remove -SANDBOX from <version> and <parent><version> tags. Then you need to add:
<resource>
<directory>src/main/resources</directory>
</resource>
to the already existing <resources> tag (right after first LICENSE+NOTICE include line 88)
This is the test code used:
package org.apache.commons.vfs2.provider.smb.test;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.auth.StaticUserAuthenticator;
import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder;
public class StandaloneMain
{
public static void main(String[] args) throws FileSystemException {
//jcifs.Config.registerSmbURLHandler();
StaticUserAuthenticator auth = new StaticUserAuthenticator("DOMAIN", "eckenfel", "SECRET");
FileSystemOptions opts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FileSystemManager fs = VFS.getManager();
if (!fs.hasProvider("smb")) throw new RuntimeException("Provide missing");
System.out.println("Connecting " + args[0] + " with " + opts);
FileObject smbFile = fs.resolveFile(args[0], opts); // added opts!
System.out.println(smbFile.exists() + " " + smbFile.getContent().getLastModifiedTime());
}
}
And this is the execution:
> set REP=C:UsersUSERNAME.m2
epository
> java -cp sandbox argetcommons-vfs2-sandbox-2.0.jar;^
core argetcommons-vfs2-2.0.jar;^
%REP%commons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;^
%REP%jcifsjcifs.8.3jcifs-0.8.3.jar;^
sandbox arget est-classes
org.apache.commons.vfs2.provider.smb.test.StandaloneMain smb://HOST/Users
Jan 05, 2015 2:40:19 PM org.apache.commons.vfs2.VfsLog info
INFORMATION: Using "C:UsersUSERNAMEAppDataLocalTempvfs_cache" as temporary files store.
Connecting smb://eckenfels02/Users with org.apache.commons.vfs2.FileSystemOptions@27dd2ec5
true 0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…