解决Opentaps/OFBiz在Eclipse启动时"Could not load VFS configuration"的问题

本文详细描述了如何解决Opentaps在Eclipse环境中启动时遇到的VFS配置重复加载导致的异常问题。通过在Opentaps根目录下创建debug-in-eclipse-hack/src目录并修改StandardFileSystemManager类,可以有效避免重复加载,进而成功在Eclipse中启动Opentaps。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在命令行使用./startofbiz.sh启动Opentaps正常, 而在Eclipse中启动时出现异常,异常信息如下: 
Java代码  收藏代码
  1. org.ofbiz.base.start.StartupException: Cannot start()  
  2. org.ofbiz.commons.vfs.CommonsVfsContainer (Initializing  
  3. StandardFileSystemManager (Could not load VFS configuration from  
  4. "file:/home/engineers/workspaces/ws-opentaps-tpg/opentaps/bin/META-INF/vfs-providers.xml ".))  
  5. at org.ofbiz.base.container.ContainerLoader.start(ContainerLoader.java:104)  
  6. at org.ofbiz.base.start.Start.startStartLoaders(Start.java:264)  
  7. at org.ofbiz.base.start.Start.startServer(Start.java:313)  
  8. at org.ofbiz.base.start.Start.start(Start.java:317)  
  9. at org.ofbiz.base.start.Start.main(Start.java:400)  
  10. org.ofbiz.base.container.ContainerException: Initializing  
  11. StandardFileSystemManager (Could not load VFS configuration from  
  12. "file:/home/engineers/workspaces/ws-opentaps-tpg/opentaps/bin/META-INF/vfs-providers.xml ".)  
  13. at  
  14. org.ofbiz.commons.vfs.CommonsVfsContainer.start(CommonsVfsContainer.java:51)  
  15. at org.ofbiz.base.container.ContainerLoader.start(ContainerLoader.java:102)  
  16. at org.ofbiz.base.start.Start.startStartLoaders(Start.java:264)  
  17. at org.ofbiz.base.start.Start.startServer(Start.java:313)  
  18. at org.ofbiz.base.start.Start.start(Start.java:317)  
  19. at org.ofbiz.base.start.Start.main(Start.java:400)  
  20. Caused by: org.apache.commons.vfs.FileSystemException: Could not load VFS  
  21. configuration from "file:/home/engineers/workspaces/ws-opentaps-tpg/opentaps/bin/META-INF  
  22. /vfs-providers.xml ".  
  23. at  
  24. org.apache.commons.vfs.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:199)  
  25. at  
  26. org.apache.commons.vfs.impl.StandardFileSystemManager.configurePlugins(StandardFileSystemManager.java:156)  
  27. at  
  28. org.apache.commons.vfs.impl.StandardFileSystemManager.init(StandardFileSystemManager.java:129)  
  29. at  
  30. org.webslinger.commons.vfs.VFSUtil.createStandardFileSystemManager(VFSUtil.java:351)  
  31. at  
  32. org.webslinger.commons.vfs.VFSUtil.createStandardFileSystemManager(VFSUtil.java:345)  
  33. at  
  34. org.ofbiz.commons.vfs.CommonsVfsContainer.start(CommonsVfsContainer.java:45)  
  35. ... 5 more  
  36. Caused by: org.apache.commons.vfs.FileSystemException: Multiple providers  
  37. registered for URL scheme "ofbiz-home".  
  38. at  
  39. org.apache.commons.vfs.impl.DefaultFileSystemManager.addProvider(DefaultFileSystemManager.java:174)  
  40. at  
  41. org.apache.commons.vfs.impl.StandardFileSystemManager.addProvider(StandardFileSystemManager.java:362)  
  42. at  
  43. org.apache.commons.vfs.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:262)  
  44. at  
  45. org.apache.commons.vfs.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:195)  
  46. ... 10 more  


网络上(包括Opentaps论坛与OFBiz Mailing Lists)所提供的解决方案是在Opentaps中禁用vfs和webslinger,即把\framework\base\config\ofbiz-containers.xml中以下两行注释掉: 
Java代码  收藏代码
  1. <container name="commons-vfs-container" class="org.ofbiz.commons.vfs.CommonsVfsContainer"/>  
  2. <container name="webslinger-container" class="org.ofbiz.webslinger.WebslingerContainer"/>  

这种解决方案能够使Opentaps启动成功,但是实际上在Opentaps真正需要使用到vfs与webslinger就显得非常无能为力. 

根据异常信息分析,原因有可能是重复加载了vfs-providers.xml(定义URL scheme为ofbiz-home的Provider).经过调试证实了笔者的猜测,在实例化org.apache.commons.vfs.impl.StandardFileSystemManager后,会调用其init方法来初始化,在init方法中调用了configurePlugins方法,以下为configurePlugins方法的代码: 
Java代码  收藏代码
  1. protected void configurePlugins() throws FileSystemException  
  2.  {  
  3.     ClassLoader cl = findClassLoader();  
  4.   
  5.     Enumeration enumResources = null;  
  6.     try  
  7.     {  
  8.         enumResources = cl.getResources(PLUGIN_CONFIG_RESOURCE);  
  9.     }  
  10.     catch (IOException e)  
  11.     {  
  12.         throw new FileSystemException(e);  
  13.     }  
  14.   
  15.     while (enumResources.hasMoreElements())  
  16.     {  
  17.         URL url = (URL) enumResources.nextElement();  
  18.         configure(url);  
  19.     }  
  20. }  

在此段代码设置断点,发现%OPENTAPS_HOME%/bin/META-INF/vfs-providers.xml被加载了两次,同时抛出了异常,这正是问题所在.那么vfs-providers.xml为什么会被加载两次,请看以下代码: 
Java代码  收藏代码
  1. protected void configurePlugins() throws FileSystemException  
  2. {  
  3. ...  
  4. enumResources = cl.getResources(PLUGIN_CONFIG_RESOURCE);  
  5. ...  
  6. }  

java.lang.ClassLoader : 
Java代码  收藏代码
  1.    public Enumeration<URL> getResources(String name) throws IOException {  
  2. Enumeration[] tmp = new Enumeration[2];  
  3. if (parent != null) {  
  4.     tmp[0] = parent.getResources(name);  
  5. else {  
  6.     tmp[0] = getBootstrapResources(name);  
  7. }  
  8. tmp[1] = findResources(name);  
  9.   
  10. return new CompoundEnumeration(tmp);  
  11.    }  

推断出vfs-providers.xml在Parent ClassLoader中被加载后,又被Current ClassCloader加载.从ClassLoder方面再深入的分析就太费时间精力了,毕竟只是在Eclipse才有这个问题.有更快速方便的方法,就是修改StandardFileSystemManager. 

在Opentaps根目录新建目录debug-in-eclipse-hack/src,在Eclipse中设置为源代码目录,把StandardFileSystemManager根据包路径拷贝进去,修改configurePlugins方法,代码如下. 
Java代码  收藏代码
  1.    protected void configurePlugins() throws FileSystemException  
  2.    {  
  3.     ClassLoader cl = findClassLoader();  
  4.   
  5.     Enumeration enumResources = null;  
  6.     try  
  7.     {  
  8.         enumResources = cl.getResources(PLUGIN_CONFIG_RESOURCE);  
  9.     }  
  10.     catch (IOException e)  
  11.     {  
  12.         throw new FileSystemException(e);  
  13.     }  
  14.       
  15.     Set set = new HashSet();  
  16.       
  17.     while (enumResources.hasMoreElements())  
  18.     {  
  19.         URL url = (URL) enumResources.nextElement();  
  20.         if (!set.contains(url.toString())){  
  21.             set.add(url.toString());  
  22.         }  
  23.     }  
  24.       
  25.     Iterator itr = set.iterator();  
  26.     while (itr.hasNext()){  
  27.         String url = (String)itr.next();  
  28.         try {  
  29.             configure(new URL(url));  
  30.         } catch (MalformedURLException e) {  
  31.             // TODO Auto-generated catch block  
  32.             e.printStackTrace();  
  33.         }  
  34.     }  
  35. }  

Opentaps启动时新的StandardFileSystemManager类会被加载. 
修改的代码会把重复的vfs-providers.xml去掉,从而解决问题. 

好了,现在重新在Eclipse中启动Opentaps.如果还出现同样的问题,则把framework/webslinger/build/lib/ofbiz-webslinger.jar删除就可解决问题.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值