JBoss wildfly 8.x提供商“;vfs“;使用java nio路径时未安装
我试图将我的spring应用程序从glassfish 4导出到JBoss wildfly 8.x或9 alpha,但当我的应用程序在代码的某些部分启动时,会抛出异常:JBoss wildfly 8.x提供商“;vfs“;使用java nio路径时未安装,java,jboss,wildfly,Java,Jboss,Wildfly,我试图将我的spring应用程序从glassfish 4导出到JBoss wildfly 8.x或9 alpha,但当我的应用程序在代码的某些部分启动时,会抛出异常: Caused by: java.lang.RuntimeException: java.nio.file.FileSystemNotFoundException: Provider "vfs" not installed at io.undertow.servlet.core.DeploymentManagerImpl.d
Caused by: java.lang.RuntimeException: java.nio.file.FileSystemNotFoundException: Provider "vfs" not installed
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:218)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
... 3 more
Caused by: java.nio.file.FileSystemNotFoundException: Provider "vfs" not installed
at java.nio.file.Paths.get(Paths.java:147) [rt.jar:1.7.0_72]
at com.springmvcangular.backend.utils.entity.BaseEntityInitializer.extendsEntities(BaseEntityInitializer.java:123)
at com.springmvcangular.backend.utils.entity.BaseEntityInitializer.initializeBaseEntities(BaseEntityInitializer.java:88)
at com.springmvcangular.backend.config.ApplicationInitializer.onStartup(ApplicationInitializer.java:60)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:178)
... 7 more
在我的类BaseEntityInitializer
中,在该异常行中,我有:
packagepath = Paths.get(this.getClass().getClassLoader()
.getResource(path.replace('.', '/')).toURI());
其中
path
是一个类似于com.something.model
的包路径,那么为什么在我的glassfish 4服务器中它可以完美工作,我需要在wildfly中使用它?我不知道wildfly中缺少了什么,也不知道我是否需要包含一些库。它碰巧在GlassFish中起作用。在ClassLoader
合同(或javaee平台规范)中,没有指定返回什么类型的URL
。在GlassFish类中,它可能碰巧是一个jar://
或文件://
URL,而恰好有一个FileSystemProvider(jar://
只是偶然的)。在WildFly中,URL
恰好是JBoss VFS URL。现在有各种各样的黑客可以让它工作,但它们都不能掩盖一个事实,那就是你依赖的是不可移植的行为。您最好使用类似于URL#openStream()
的东西,它是可移植的,因此应该可以在任何地方使用
更新
您可以尝试在编译时执行更多操作。选择包括:
- 在编译时使用Javassist进行转换。这也减少了与随WildFly提供的Javassist发生冲突的机会
- 在编译时收集有关资源的信息,并将其存储在已知位置的文件中。您可以在多个JAR中使用相同的文件名,因为
可以返回多个结果ClassLoader\getResources(String)
如果您提供有关您试图解决的问题的更具体的信息,我可能会给出更具体的答案。这是我的解决方案如何在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());
}
List fileNames=newlinkedlist();
URL resourceUrl=getClass().getResource(“/your/path”);
VirtualJarInputStream VirtualJarInputStream=(VirtualJarInputStream)resourceUrl.openStream();
JarEntry next=null;
while((next=virtualJarInputStream.getNextJarEntry())!=null){
add(next.getName());
}
导入org.jboss.vfs.VirtualFile;//https://mvnrepository.com/artifact/org.jboss/jboss-vfs
URLConnection connection=Objects.requirennull(getClass().getClassLoader().getResource(“/template/cyber”).openConnection();
VirtualFile VirtualFile=(VirtualFile)connection.getContent();
Stream walk=Files.walk(path.get(virtualFile.getPhysicalFile().toURI());
List result=walk.filter(Files::isRegularFile).map(Path::toString.collect(Collectors.toList());
谢谢,您是否有代码示例或url,我可以在其中看到如何将其用于Paths类?您需要路径做什么?您只是想读取资源还是要列出文件夹中的所有资源?我需要读取文件夹(包)中的所有资源,并获取它们的名称,如com.package.otherpachage.classname,因为我使用的是javassist,所以如何使用inputstreams读取包资源,或者如何为java nio安装vfs?我找不到关于它的任何东西
import org.jboss.vfs.VirtualFile; // https://mvnrepository.com/artifact/org.jboss/jboss-vfs
URLConnection connection = Objects.requireNonNull(getClass().getClassLoader().getResource("/template/cyber")).openConnection();
VirtualFile virtualFile = (VirtualFile) connection.getContent();
Stream<Path> walk = Files.walk(Paths.get(virtualFile.getPhysicalFile().toURI()));
List<String> result = walk.filter(Files::isRegularFile).map(Path::toString).collect(Collectors.toList());