【问题标题】:Add files to current classpath of jar file将文件添加到 jar 文件的当前类路径
【发布时间】:2021-04-22 20:50:24
【问题描述】:

我有一个由 spring 批处理应用程序 创建的 jar,我正在使用 config.proprerties,但我需要此文件位于 jar 的 外部。 我的 config.properties 位于“var/user/config.properties”位置,并且我使用 command:

运行了 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 Classpath + /var/user/config.properties”。 有什么想法吗?

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

【问题讨论】:

    标签: java jar properties classpath


    【解决方案1】:

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

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

    尝试:

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

    【讨论】:

    • 它有效,谢谢。只是有必要将主类放在 es.exp.exp.config.BatchConfiguration 之前。
    猜你喜欢
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    相关资源
    最近更新 更多