簡體   English   中英

OSGI / Equinox捆綁資源:URI方案不是文件

[英]OSGI/Equinox Bundle Resource: URI Scheme is not a file

我有一個在Equinox容器中運行的插件。 在插件jar中,包含一個/ bin目錄,其中包含我要運行的可執行文件以及關聯的共享庫。 我正在嘗試獲取可執行文件(/ bin)的父路徑,但遇到以下異常:

    Exception in thread "SpringOsgiExtenderThread-88" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testLauncher' defined in URL [bundleentry://105.fwk10703525/META-INF/spring/service.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.test.TestLauncher]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: URI scheme is not "file"
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:288)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
        at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
        at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
        at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.test.TestLauncher]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: URI scheme is not "file"
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:108)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
        ... 16 more
Caused by: java.lang.IllegalArgumentException: URI scheme is not "file"
        at java.io.File.<init>(File.java:366)
        at com.test.TestLauncher.<init>(TestLauncher.java:23)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
        ... 18 more

下面的代碼顯示了我的構造函數試圖獲取Resource變量的父路徑(/ bin)。 新的File(binPath.getURI())命令將引發異常。 使用下面的spring上下文定義傳遞資源變量。

public Launcher(Resource resource) {
    try {
        binFile = resource.getURL().getFile();            
        String binPath = new File(binPath.getURI()).getParentFile().getAbsolutePath();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.out.println("TestLauncher Exception found");
        e.printStackTrace();
    }
}

Spring上下文定義:

<bean id="testResource" class="org.springframework.core.io.ClassPathResource">  
    <constructor-arg value="\bin\test" />
</bean>

我認為您需要做的就是將路徑值作為文件uri提供,例如:

<bean id="testResource" class="org.springframework.core.io.ClassPathResource">  
  <constructor-arg value="file:../test" />
</bean>

在這里,我只是根據我認為是您的類路徑來猜測您需要的路徑。 您可能需要嘗試不同的路徑值才能使它起作用。

祝好運!

暫無
暫無

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

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