将文件添加到 jar 文件的当前类路径

时间:2021-01-18 14:34:49

标签: java jar properties classpath

我有一个由 spring 批处理应用程序 创建的 jar,我使用的是 config.proprerties 但我需要这个文件位于 jar 的外部。 我在“var/user/config.properties”位置有 config.properties 并且我已经使用 命令运行了 jar:

java -classpath "/var/user/config.properties" batch-0.0.1-SNAPSHOT.jar es.exp.exp.config.BatchConfiguration someJob date=20210115 systemDate=15

但我认为参数 -classpath 设置了所有类路径,我的意思是类路径参数删除了 jar 类路径并只将 /var/user/config.properties 放在类路径中。 我不需要这个,我需要类路径是“实际的 jar 类路径 + /var/user/config.properties”。 有什么想法吗?

对不起,我的英语不是我的母语。

1 个答案:

答案 0 :(得分:0)

-classpath(或 -cp)中的类路径元素在 Linux 上用“:”或“;”分隔在 Windows 中。

此外,如果您希望在类路径中访问 config.properties,您不需要在路径中添加文件,而是在包含该文件的目录中添加。

尝试:

java -cp /var/user:batch-0.0.1-SNAPSHOT.jar es.tirea.cicosgw.config.BatchConfiguration someJob date=20210115 systemDate=15
相关问题