Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在创建可执行jar时,如何引用本地文件并将其包含在maven程序集中?_Java_Maven_Jar_Dependencies_Executable Jar - Fatal编程技术网

Java 在创建可执行jar时,如何引用本地文件并将其包含在maven程序集中?

Java 在创建可执行jar时,如何引用本地文件并将其包含在maven程序集中?,java,maven,jar,dependencies,executable-jar,Java,Maven,Jar,Dependencies,Executable Jar,我试图组装我的可执行jar,但我不知道在构建项目时如何在项目中包含本地index.aff和index.dic文件。当我执行jar文件时,它根本不知道文件在哪里,并抛出一个file not found异常。在编译时,它工作得很好,但在执行我的jar文件时,它似乎没有被包括在内。不完全确定如何解决这个问题。我如何在jar中包含本地文件,而不必携带外部索引。*文件 这是我的maven命令(它成功构建,但没有索引文件): $mvn汇编:assembly-Dfile=src/lib/language-al

我试图组装我的可执行jar,但我不知道在构建项目时如何在项目中包含本地index.aff和index.dic文件。当我执行jar文件时,它根本不知道文件在哪里,并抛出一个file not found异常。在编译时,它工作得很好,但在执行我的jar文件时,它似乎没有被包括在内。不完全确定如何解决这个问题。我如何在jar中包含本地文件,而不必携带外部索引。*文件

这是我的maven命令(它成功构建,但没有索引文件):

$mvn汇编: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>

path/to/the/resources'/目录
特定/文件
特定/文件
path/in/jar/where/to/put/resources
默认情况下,将包括的所有内容。
,都是可选的,只需使用您需要的选项即可。
您可以找到更多的示例。

这是可行的,但是需要为构建更改参考路径。有没有办法在pom.xml文件中指定它,或者每次在java代码中我都需要手动更改它?如果您的意思是在IDE中运行和在jar中运行时路径不同,那么您可以让IDE直接执行jar