簡體   English   中英

使用java nio Paths時未安裝JBoss wildfly 8.x Provider“vfs”

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

我正在嘗試將我的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

在我的類BaseEntityInitializer中,該異常行我有:

packagepath = Paths.get(this.getClass().getClassLoader()
                            .getResource(path.replace('.', '/')).toURI());

其中path是一個像com.something.model這樣的包路徑,為什么在我的glassfish 4服務器中這個工作完美,我需要在wildfly中使用它? 我不知道wildfly中缺少什么,或者我是否需要包含一些庫。

它碰巧在GlassFish中偶然發揮作用。 ClassLoader契約(或Java EE平台規范)中沒有指定您獲取的URL類型。 在GlassFish ClasLoder中,它可能恰好是一個jar://file:// URL恰好是FileSystemProvider( jar://只是偶然BTW)。 在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());
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM