我正在尝试组装我的可执行jar,但是当我构建它时,我不知道如何在项目中包含本地index.aff和index.dic文件。当我执行jar文件时,它根本不知道文件的位置并抛出文件未找到的异常。它在编译期间工作正常,但是当执行我的jar文件时,似乎没有包含它。不完全确定如何解决这个问题。如何在我的jar中包含本地文件而不必带外部索引。*文件?
这是我的maven命令(它构建成功,但没有索引文件):
$ mvn assembly:assembly -Dfile = src / lib / language-all-4.4.jar -DomFile = pom.xml -Durl = file:/// src / lib / en-US / * -X
public HunSpellChecker(){
hunspell = Hunspell.getInstance();
dir = "src/lib/en-US"; //jar doesn't know how to reference this.
try{
en = hunspell.getDictionary(dir + "/index" );
} catch (Exception e){
System.out.println(e.getMessage());
}
}
要使用Maven在jar中包含非Java代码的文件,您只需修改pom.xml中的构建节点:
<resources>
<resource>
<directory>path/to/the/resources'/directory</directory>
<includes>
<include>specific/file</include>
</includes>
<excludes>
<exclude>specific/file</exclude>
</excludes>
<targetPath>path/in/jar/where/to/put/resources</targetPath>
</resource>
</resources>
默认情况下,将包含<directory>的所有内容。 <directory>,<includes>,<excludes>和<targetPath>都是选项,只需使用您需要的选项。你可以找到更多例子here。