在创建可执行 jar 时如何引用本地文件并将其包含在我的 maven 程序集中?
how can I reference a local file and include it with my maven assembly when creating an executable jar?
我正在尝试 assemble 我的可执行 jar,但我不知道如何在构建时将本地 index.aff 和 index.dic 文件包含在项目中它。当我执行 jar 文件时,它根本不知道文件在哪里并抛出一个文件未找到的异常。它在编译时工作正常,但在执行我的 jar 文件时它似乎没有被包含在内。不完全确定如何解决这个问题。如何在不带外部 index.* 文件的情况下将本地文件包含在我的 jar 中?
这是我的 maven 命令(构建成功但没有索引文件):
$ mvn assembly:assembly -Dfile=src/lib/language-all-4.4.jar -DpomFile=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>
默认情况下,将包含 的所有内容。
, , 和 都是可选的,只用你需要的。
您可以找到更多示例 here.
我正在尝试 assemble 我的可执行 jar,但我不知道如何在构建时将本地 index.aff 和 index.dic 文件包含在项目中它。当我执行 jar 文件时,它根本不知道文件在哪里并抛出一个文件未找到的异常。它在编译时工作正常,但在执行我的 jar 文件时它似乎没有被包含在内。不完全确定如何解决这个问题。如何在不带外部 index.* 文件的情况下将本地文件包含在我的 jar 中?
这是我的 maven 命令(构建成功但没有索引文件):
$ mvn assembly:assembly -Dfile=src/lib/language-all-4.4.jar -DpomFile=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>
默认情况下,将包含