簡體   English   中英

在創建可執行 jar 時,如何引用本地文件並將其包含在我的 Maven 程序集中?

[英]how can I reference a local file and include it with my maven assembly when creating an executable jar?

我正在嘗試組裝我的可執行 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>

默認情況下,將包含 <directory> 的所有內容。
<directory>、<includes>、<excludes> 和 <targetPath> 都是可選的,使用你需要的即可。 您可以在此處找到更多示例。

暫無
暫無

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

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