JBoss wildfly 8.x Provider “vfs” not installed when using java nio Paths

浪子不回头ぞ 提交于 2019-11-30 14:11:47

It happens to work by chance in GlassFish. Nowhere in the ClassLoader contract (or the Java EE platform specification) is it specified what kind of URL you get back. In the GlassFish ClasLoder it probably happens to be a jar:// or file:// URL for which there happens to be a FileSystemProvider (jar:// only by accident BTW). In WildFly the URL happens to be a JBoss VFS URL. There are various hacks that you can apply to make it work for now but they all can't hide the fact that you're relying on not portable behavior. You're better off using something like URL#openStream() instead which is portable and should therefore work everywhere.

Update

What you can try to do is doing more at compile time. Options include:

  • Do the transformation with Javassist at compile time. This also reduces the chances of conflicts with the Javassist shipping with WildFly.
  • Gather the information about the resources at compile time and store it in a file at a well known location. You can have the same file name in multiple JARs as ClassLoader#getResources(String) can return multiple results.

If you provide more specific information about the problem you're trying to solve I may be able to give more specific answers.

This is my solution how to iterate over files/directories in Wildfly:

List<String> fileNames = new LinkedList<>();
URL resourceUrl = getClass().getResource("/your/path");
VirtualJarInputStream virtualJarInputStream = (VirtualJarInputStream) resourceUrl.openStream();
JarEntry next = null;
while ((next = virtualJarInputStream.getNextJarEntry()) != null) {
    fileNames.add(next.getName());
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!