2015-06-05 42 views
5

我添加了一个资源用于一个模块如下:NetBeans平台:InstalledFileLocator

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>nbm-maven-plugin</artifactId> 
    <extensions>true</extensions> 
    <configuration> 
     <moduleType>eager</moduleType> 
     <nbmResources>      
      <nbmResource> 
       <directory>${basedir}/resources</directory> 
       <targetPath>resources</targetPath> 
       <includes> 
        <include>*.db</include> 
       </includes> 
       <excludes> 
        <exclude>*trace*</exclude> 
       </excludes> 
      </nbmResource> 
     </nbmResources> 
    </configuration> 
</plugin> 

该文件示出了在NetBeans应用:target/app name/app name/resources/card_manager.mv.db。这看起来很好。

现在,我试图让该文件位置如下:

File db = InstalledFileLocator.getDefault().locate("card_manager.mv.db", 
        "module.codename.base", false); 

但DB总是空。任何想法?

回答

0

试试这个代码...

File file = InstalledFileLocator.getDefault().locate("myfile", null, false); 
if (file == null) 
{ 
    file = new File(Places.getUserDirectory() + File. separator + "myfile"); 
} 

或者你试过资源/ card_manager.mv.db?我确定应用程序路径(应用程序名称)和集群名称(第二个应用程序名称)从locate()中排除,但我相信您必须包含资源/路径。

+0

会试一试并回报。 – javydreamercsw

+0

没有工作,但我知道我可以使它改变资源位置等,但不是我想要的。我需要使用InstalledFileLocator,因为各种模块可能有自己的这个文件版本,我需要通过codenamebase来定位它。 – javydreamercsw

+0

即使赏金到期,我也会给出一个很好的答案赏金点数。 – javydreamercsw

0

修改您的pom,以便card_manager.mv.db被复制到classes文件夹而不是resources文件夹并从您的类加载器中获取文件。

+0

我知道我可以让它改变资源位置等,但不是我想要的。我需要使用InstalledFileLocator,因为各种模块可能有自己的这个文件版本,我需要通过codenamebase来定位它。 – javydreamercsw

+0

即使赏金到期,我也会给出一个很好的答案赏金点数。 – javydreamercsw