使用java nio Paths时未安装JBoss wildfly 8.x Provider"vfs"

Die*_*nci 6 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.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
Run Code Online (Sandbox Code Playgroud)

在我的班级BaseEntityInitializer中,我有以下例外情况:

packagepath = Paths.get(this.getClass().getClassLoader()
                            .getResource(path.replace('.', '/')).toURI());
Run Code Online (Sandbox Code Playgroud)

其中,path它的一个包路径一样com.something.model,为什么在我的GlassFish 4服务器这完美的作品和我需要在wildfly用呢?我不知道wildfly中缺少什么,或者我是否需要包含一些库.

Phi*_*all 5

它碰巧在 GlassFish 中起作用。无处的ClassLoader合同(或Java EE平台规范)是指定什么样的URL,你回来。在 GlassFish ClasLoder 中,它可能恰好是一个jar://file://URL,恰好有一个 FileSystemProvider(jar://顺便说一句,只是偶然)。在 WildFly 中,它URL恰好是一个 JBoss VFS URL。您可以应用各种技巧来使其暂时工作,但它们都无法掩盖您依赖不可移植行为的事实。你最好使用类似的东西URL#openStream(),它是便携式的,因此应该可以在任何地方工作。

更新

您可以尝试做的是在编译时做更多的事情。选项包括:

  • 在编译时使用 Javassist 进行转换。这也减少了与带有 WildFly 的 Javassist 版本发生冲突的可能性。
  • 在编译时收集有关资源的信息并将其存储在已知位置的文件中。您可以在多个 JAR 中使用相同的文件名,因为ClassLoader#getResources(String)可以返回多个结果。

如果您提供有关您要解决的问题的更具体的信息,我可能会给出更具体的答案。

  • 我需要读取文件夹(包)中的所有资源并获取它们的名称,例如 com.package.otherpachage.classname,因为我使用的是 javassist,所以我如何使用输入流读取包资源或如何为 java nio 安装 vfs?我没有找到任何关于它的信息 (3认同)