首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

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

2012-07-23 
解决Opentaps/OFBiz在Eclipse启动时Could not load VFS configuration的问题在命令行使用./startofbiz.s

解决Opentaps/OFBiz在Eclipse启动时"Could not load VFS configuration"的问题
在命令行使用./startofbiz.sh启动Opentaps正常, 而在Eclipse中启动时出现异常,异常信息如下:

org.ofbiz.base.start.StartupException: Cannot start()org.ofbiz.commons.vfs.CommonsVfsContainer (InitializingStandardFileSystemManager (Could not load VFS configuration from"file:/home/engineers/workspaces/ws-opentaps-tpg/opentaps/bin/META-INF/vfs-providers.xml ".))at org.ofbiz.base.container.ContainerLoader.start(ContainerLoader.java:104)at org.ofbiz.base.start.Start.startStartLoaders(Start.java:264)at org.ofbiz.base.start.Start.startServer(Start.java:313)at org.ofbiz.base.start.Start.start(Start.java:317)at org.ofbiz.base.start.Start.main(Start.java:400)org.ofbiz.base.container.ContainerException: InitializingStandardFileSystemManager (Could not load VFS configuration from"file:/home/engineers/workspaces/ws-opentaps-tpg/opentaps/bin/META-INF/vfs-providers.xml ".)atorg.ofbiz.commons.vfs.CommonsVfsContainer.start(CommonsVfsContainer.java:51)at org.ofbiz.base.container.ContainerLoader.start(ContainerLoader.java:102)at org.ofbiz.base.start.Start.startStartLoaders(Start.java:264)at org.ofbiz.base.start.Start.startServer(Start.java:313)at org.ofbiz.base.start.Start.start(Start.java:317)at org.ofbiz.base.start.Start.main(Start.java:400)Caused by: org.apache.commons.vfs.FileSystemException: Could not load VFSconfiguration from "file:/home/engineers/workspaces/ws-opentaps-tpg/opentaps/bin/META-INF/vfs-providers.xml ".atorg.apache.commons.vfs.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:199)atorg.apache.commons.vfs.impl.StandardFileSystemManager.configurePlugins(StandardFileSystemManager.java:156)atorg.apache.commons.vfs.impl.StandardFileSystemManager.init(StandardFileSystemManager.java:129)atorg.webslinger.commons.vfs.VFSUtil.createStandardFileSystemManager(VFSUtil.java:351)atorg.webslinger.commons.vfs.VFSUtil.createStandardFileSystemManager(VFSUtil.java:345)atorg.ofbiz.commons.vfs.CommonsVfsContainer.start(CommonsVfsContainer.java:45)... 5 moreCaused by: org.apache.commons.vfs.FileSystemException: Multiple providersregistered for URL scheme "ofbiz-home".atorg.apache.commons.vfs.impl.DefaultFileSystemManager.addProvider(DefaultFileSystemManager.java:174)atorg.apache.commons.vfs.impl.StandardFileSystemManager.addProvider(StandardFileSystemManager.java:362)atorg.apache.commons.vfs.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:262)atorg.apache.commons.vfs.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:195)... 10 more


网络上(包括Opentaps论坛与OFBiz Mailing Lists)所提供的解决方案是在Opentaps中禁用vfs和webslinger,即把\framework\base\config\ofbiz-containers.xml中以下两行注释掉:
<container name="commons-vfs-container" name="code">protected void configurePlugins() throws FileSystemException {ClassLoader cl = findClassLoader();Enumeration enumResources = null;try{enumResources = cl.getResources(PLUGIN_CONFIG_RESOURCE);}catch (IOException e){throw new FileSystemException(e);}while (enumResources.hasMoreElements()){URL url = (URL) enumResources.nextElement();configure(url);}}

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

java.lang.ClassLoader :
    public Enumeration<URL> getResources(String name) throws IOException {Enumeration[] tmp = new Enumeration[2];if (parent != null) {    tmp[0] = parent.getResources(name);} else {    tmp[0] = getBootstrapResources(name);}tmp[1] = findResources(name);return new CompoundEnumeration(tmp);    }

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

在Opentaps根目录新建目录debug-in-eclipse-hack/src,在Eclipse中设置为源代码目录,把StandardFileSystemManager根据包路径拷贝进去,修改configurePlugins方法,代码如下.
    protected void configurePlugins() throws FileSystemException    {ClassLoader cl = findClassLoader();Enumeration enumResources = null;try{enumResources = cl.getResources(PLUGIN_CONFIG_RESOURCE);}catch (IOException e){throw new FileSystemException(e);}Set set = new HashSet();while (enumResources.hasMoreElements()){URL url = (URL) enumResources.nextElement();if (!set.contains(url.toString())){set.add(url.toString());}}Iterator itr = set.iterator();while (itr.hasNext()){String url = (String)itr.next();try {configure(new URL(url));} catch (MalformedURLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

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

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

热点排行