2

I'm using the vfs2 (not vfs) to access ftp. Now I also use the smb protocol but it does not work. I always get the Exception:

ClassNotFoundException: org.apache.commons.vfs.provider.FileProvider

But as I'm using vfs2 it is weird that it searches for classes with commons.vfs.provider and not commons.vfs2.provider - because in vfs2 the class exists.

Do I miss a library (jar)?

I have at the moment: commons-vfs2-2.0.jar, commons-vfs2-sandbox-2.0.jar (had to be added to find smb protocol), jcifs-1.3.17.jar, commons-net-3.3.jar, commons-collections-3.2.1.jar, commons-logging-1.1.1.jar and may more..

Here my complete StackTrace:

org.apache.commons.vfs2.FileSystemException: Could not create a file system manager of class "org.apache.commons.vfs2.impl.StandardFileSystemManager".
    at org.apache.commons.vfs2.VFS.createManager(VFS.java:99)
    at org.apache.commons.vfs2.VFS.getManager(VFS.java:50)
    at com.avintis.framework.service.DbAccessImpl.saveArchiveData(DbAccessImpl.java:1188)
    at com.avintis.framework.service.DbAccessImpl.saveMessageData(DbAccessImpl.java:905)
    at com.avintis.framework.service.DbAccessImpl.saveMessage(DbAccessImpl.java:417)
    at com.avintis.framework.service.ImportTrackingMsgServiceImpl.importFile(ImportTrackingMsgServiceImpl.java:77)
    at com.avintis.framework.service.ImportTrackingMsgServiceImpl.importFile(ImportTrackingMsgServiceImpl.java:30)
    at com.avintis.framework.watcher.service.WatcherServiceImpl.addTrackingMessages(WatcherServiceImpl.java:87)
    at com.avintis.framework.watcher.service.WatcherServiceImpl.watchForFiles(WatcherServiceImpl.java:34)
    at com.avintis.framework.schedule.WatcherJob.executeInternal(WatcherJob.java:30)
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:534)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/vfs/provider/FileProvider
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2854)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.createInstance(StandardFileSystemManager.java:485)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.addProvider(StandardFileSystemManager.java:371)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:270)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:195)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.configurePlugins(StandardFileSystemManager.java:154)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.init(StandardFileSystemManager.java:126)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.commons.vfs2.VFS.createManager(VFS.java:88)
    ... 12 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.vfs.provider.FileProvider
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    ... 30 more
Philipp
  • 4,645
  • 3
  • 47
  • 80

1 Answers1

2

In the first sight it looks like you need the commons-vfs.jar not the commons-vfs2-2.0.jar because the packagename in commons-vfs2-2.0.jar is org.apache.commons.vfs2.provider.jar. But this may cause problems with mixing up vfs and vfs2 classes and not work.

So make sure you have following jars (only vfs2) loaded:

  • commons-vfs2-2.0.jar
  • commons-vfs2-sandbox-2.0.jar
  • jcifs-1.3.17.jar
  • And other depending commons (net, logging,...)

Then also add the vfs-providers.xml inside your META-INF pointing to the correct class for the SmbFileProvider:

<provider class-name="org.apache.commons.vfs2.provider.smb.SmbFileProvider">
    <scheme name="smb"/>
    <if-available class-name="jcifs.smb.SmbFile"/>
</provider>
Philipp
  • 4,645
  • 3
  • 47
  • 80
Jens
  • 67,715
  • 15
  • 98
  • 113
  • 1
    This gives the next Exception: `org.apache.commons.vfs.provider.smb.SmbFileProvider cannot be cast to org.apache.commons.vfs2.provider.FileProvider`. Somewhere the vfs2 library is mixing up with the old vfs library – Philipp Sep 04 '14 at 12:18
  • But where? I only have vfs2 libraries. As you can see in the above StackTrace - it is the vfs2 Loader that automatically tries to load a vfs class... – Philipp Sep 04 '14 at 12:20
  • @FiveO Do you have also changed the sanbox.jar? – Jens Sep 04 '14 at 12:22
  • @FiveO It looks like the class wich is loaded comes from a configuration file. May you have a configuration problem. Where you configure it? – Jens Sep 04 '14 at 12:26
  • I haven't modified any jar (But the sandbox may be suspicious - the official site does not give a download). I don't have a configuration file (vfs-providers.xml) - it should take the default. – Philipp Sep 04 '14 at 13:05
  • @FiveO What is the Default? – Jens Sep 04 '14 at 14:32
  • I don't know - this is what VFS2 is telling, but maybe smb is not in the defaults.. http://commons.apache.org/proper/commons-vfs/api.html – Philipp Sep 05 '14 at 06:08
  • Do you have an example of the vfs-providers.xml with smb configuration? – Philipp Sep 05 '14 at 06:11
  • @FiveO No sorry i havn't – Jens Sep 05 '14 at 06:16
  • Seems like all build of the vfs sandbox point to old classes. And the download of the sandbox on the apache commons vfs page is not available. I'm really stuck here - just save a file to a Windows Share... – Philipp Sep 05 '14 at 06:22
  • 1
    You won't believe it! It worked! Had to add the sandbox-2.0 and add the provider with vfs2 in the vfs-providers.xml. I'll modify your answer and add these parts! Thanks for your great help - felt not alone with my problem ;-) – Philipp Sep 05 '14 at 06:28
  • BTW: to build a VFS 2.0 sandbox jar with working vfs-provider.xml you can check this answer: http://stackoverflow.com/a/27780881/13189 – eckes Jan 05 '15 at 16:35