OSGi noClassDefFound for java.nio.files.FileSystems$DefaultFileSystemHolder

OSGi noClassDefFound for java.nio.files.FileSystems$DefaultFileSystemHolder,java,maven,osgi,filesystemwatcher,Java,Maven,Osgi,Filesystemwatcher,在我们的应用程序中,我们使用ini文件来配置OSGi应用程序。现在我考虑添加一个WatchService来检测更改,并在必要时重新加载修改过的文件 到目前为止,我找到了多个教程。它们中的大多数是相似的,结果如下: . 我是这样采纳的: 36: public Ini(final File file) throws IOException { if (!file.exists()) { throw new IOException("Ini-File does no

在我们的应用程序中,我们使用ini文件来配置OSGi应用程序。现在我考虑添加一个WatchService来检测更改,并在必要时重新加载修改过的文件

到目前为止,我找到了多个教程。它们中的大多数是相似的,结果如下: . 我是这样采纳的:

36: public Ini(final File file) throws IOException {
       if (!file.exists()) {
           throw new IOException("Ini-File does not exist.");
       } else if (!file.canRead()) {
40:         throw new IOException("Ini-File is not readable.");
       }
       iniFile = file;

        FileSystem fileSystem = FileSystems.getFileSystem(file.toURI());
45:     Path test = fileSystem.getPath(file.getAbsolutePath());
        Path ini = FileSystems.getDefault().getPath(file.getParent(), file.getName());
        Logger.debug(ini.toString());
        readIni(ini);

50:     service = FileSystems.getDefault().newWatchService();
        file.getParentFile().toPath().register(service, ENTRY_MODIFY);

        Thread watcher = new Thread(() -> {
            // noinspection InfiniteLoopStatement
55:             while (true) {
                WatchKey key = null;
                try {
                    key = service.take();
                    for (WatchEvent<?> event : key.pollEvents()) {
60:                     Logger.debug("event received");
                        if (event.kind() != ENTRY_MODIFY) {
                            continue;
                        }
                        WatchEvent<Path> ev = (WatchEvent<Path>) event;
65:
                        File filename = ev.context().toFile();
                        if (filename.getAbsolutePath().equals(iniFile.getAbsolutePath())) {
                            Logger.debug(filename.getName() + " has changed");

70:                         config = new HashMap<>();
                            try {
                                readIni(filename.toPath());
                            } catch(IOException e) {
                                Logger.warning(e);
75:                         }
                        }
                    }
                } catch (Exception e) {
                    Logger.warning(e);
80:             }
                if (key != null)
                    key.reset();
            }
        });
85: 
        watcher.start();
    }
36:public Ini(最终文件)引发IOException{
如果(!file.exists()){
抛出新IOException(“Ini文件不存在”);
}else如果(!file.canRead()){
40:抛出新IOException(“Ini文件不可读”);
}
iniFile=文件;
FileSystem FileSystem=FileSystems.getFileSystem(file.toURI());
45:Path test=fileSystem.getPath(file.getAbsolutePath());
路径ini=FileSystems.getDefault().getPath(file.getParent(),file.getName());
Logger.debug(ini.toString());
雷迪尼;
50:service=FileSystems.getDefault().newWatchService();
file.getParentFile().toPath().register(服务、条目和修改);
线程观察程序=新线程(()->{
//noinspection无穷远语句
55:while(正确){
WatchKey=null;
试一试{
key=service.take();
for(WatchEvent事件:key.pollEvents()){
60:Logger.debug(“接收到事件”);
if(event.kind()!=ENTRY\u MODIFY){
继续;
}
WatchEvent ev=(WatchEvent)事件;
65:
文件名=ev.context().toFile();
如果(filename.getAbsolutePath().equals(iniFile.getAbsolutePath())){
Logger.debug(filename.getName()+“已更改”);
70:config=newhashmap();
试一试{
readIni(filename.toPath());
}捕获(IOE异常){
3.警告(e);
75:                         }
}
}
}捕获(例外e){
3.警告(e);
80:             }
if(key!=null)
键。重置();
}
});
85: 
watcher.start();
}
创建新实例时,我首先检查文件是否存在。在这之后,我想创建一个WatchService来分析这个配置文件(首先只有这个配置文件。之后,我将为所有加载的文件更改为1个WatchService)

有几行(44-46)以不同的方式做同样的事情。他们都没有工作

现在,当我创建这样一个Ini文件时,felix告诉我:

[ERROR]  : java.lang.NoClassDefFoundError: Could not initialize class java.nio.file.FileSystems$DefaultFileSystemHolder
java.lang.IllegalStateException: java.lang.NoClassDefFoundError: Could not initialize class java.nio.file.FileSystems$DefaultFileSystemHolder
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:171)
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java)
    at org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:560)
    at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:440)
    at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179)
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319)
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240)
    at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:312)
    at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:306)
    at org.apache.felix.ipojo.extender.internal.queue.JobInfoCallable.call(JobInfoCallable.java:114)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class java.nio.file.FileSystems$DefaultFileSystemHolder
    at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
    at java.nio.file.spi.FileSystemProvider.installedProviders(FileSystemProvider.java:156)
    at java.nio.file.FileSystems.getFileSystem(FileSystems.java:219)
    at df.core.config.internal.Ini.<init>(Ini.java:44)
    at df.core.config.internal.ConfigImpl.__M_addConfig(ConfigImpl.java:180)
    at df.core.config.internal.ConfigImpl.addConfig(ConfigImpl.java)
    at df.core.config.api.Config$$Proxy.addConfig(Unknown Source)
    at df.playground.IniTest.__M_validate(IniTest.java:24)
    at df.playground.IniTest.validate(IniTest.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.felix.ipojo.util.Callback.call(Callback.java:237)
    at org.apache.felix.ipojo.util.Callback.call(Callback.java:193)
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86)
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:162)
    ... 13 more
[错误]:java.lang.NoClassDefFoundError:无法初始化类java.nio.file.FileSystems$DefaultFileSystemHolder
java.lang.IllegalStateException:java.lang.NoClassDefFoundError:无法初始化类java.nio.file.FileSystems$DefaultFileSystemHolder
位于org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.\uu M_stateChanged(LifecycleCallbackHandler.java:171)
位于org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java)
位于org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:560)
位于org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:440)
位于org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179)
位于org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319)
位于org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240)
位于org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:312)
位于org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:306)
位于org.apache.felix.ipojo.extender.internal.queue.JobInfoCallable.call(JobInfoCallable.java:114)
在java.util.concurrent.FutureTask.run(FutureTask.java:266)处
位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
运行(Thread.java:745)
原因:java.lang.NoClassDefFoundError:无法初始化类java.nio.file.FileSystems$DefaultFileSystemHolder
位于java.nio.file.FileSystems.getDefault(FileSystems.java:176)
位于java.nio.file.spi.FileSystemProvider.installedProviders(FileSystemProvider.java:156)
位于java.nio.file.FileSystems.getFileSystem(FileSystems.java:219)
位于df.core.config.internal.Ini。(Ini.java:44)
位于df.core.config.internal.ConfigImpl.\uu M\u addConfig(ConfigImpl.java:180)
位于df.core.config.internal.ConfigImpl.addConfig(ConfigImpl.java)
位于df.core.config.api.config$$Proxy.addConfig(未知源)
在df.playdry.IniTest.\u M\u验证(IniTest.java:24)
在df.playdry.IniTest.validate(IniTest.java)中
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:483)
位于org.apache.felix.ipojo.util.Callback.call(Callback.java:237)
位于org.apache.felix.ipojo.util.Callback.call(Callback.java:193)
在org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86)上
位于org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.\uu M_stateChanged(LifecycleCallbackHandler.java:162)
... 还有13个
这说明我在第44行搜索文件系统对象。我是否因为代码找不到DefaultFileSystem而做错了什么
org.osgi.framework.bootdelegation=sun.nio.*