2012-12-07 59 views
0

嗨我想在OpenNLP中使用标记器来开发一个Maven项目。它需要加载本地文件,但我不知道如何将其添加到项目中,以便即使在其他计算机上启动该项目时仍然可以工作。如下所示,该项目需要加载这个本地文件,我应该如何配置文件以添加到项目中?如何将本地文件添加到maven项目中?

InputStream modelIn; 
    try { 
     modelIn = new FileInputStream("E:\\en-token.bin"); 
     // Make sure the "en-token.bin" file is already in your local disk 

     TokenizerModel model = null; 
     try { 
      model = new TokenizerModel(modelIn); 
     } catch (IOException ex) { 
      ex.printStackTrace(); 
     } finally { 
      if (modelIn != null) { 
       try { 
        modelIn.close(); 
       } catch (IOException e) { 
       } 
      } 
     } 
     Tokenizer tokenizer = new TokenizerME(model); 
     String tokens[] = tokenizer.tokenize(string); 
     List<String> tokenResult = Arrays.asList(tokens); 
     return tokenResult; 

    } catch (FileNotFoundException ex) { 
     return null; 
    } 
+0

这是一种测试资源文件还是生产期间需要的文件?它应该被打包到你的jar /档案中吗? – khmarbaise

+0

这是将单词分词为单独章节的模型。我将把代码的其余部分放在这里。 –

+0

这意味着它应该是包的一部分。 – khmarbaise

回答

1

这种类型的文件应该放在的src/main /资源文件夹将被打包成jar文件。

+0

我把它放到资源中,但不知道如何将它打包成jar文件。它现在仍然是一个.bin文件。 –

+0

如果你做一个** mvn包**,它会被自动打包到jar文件中。 – khmarbaise

+0

我跑这个,但显示不被识别为内部或外部命令。对不起,我对Java的东西很新,所以打包文件看起来有些复杂。但会继续尝试其他方式来装入罐子里 –

相关问题