添加属性文件以构建可运行jar的路径 [英] Add properties file to build path of runnable jar

查看:83
本文介绍了添加属性文件以构建可运行jar的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将一些属性文件添加到可运行jar文件的类路径中?
我尝试了以下解决方案解决方案:

is it possible to add to the classpath of a runnable jar file some properties file? I tryed these solutions solutions:


  1. 使用以下命令运行可执行文件:

  1. running the executable file using the following command:

java -cp ../prop_dir/prop1.properties;../prop_dir/prop2.properties -jar MyRunnableJar.jar

java -cp ../prop_dir/prop1.properties;../prop_dir/prop2.properties -jar MyRunnableJar.jar

添加到清单文件中(在类路径部分中)

adding to the MANIFEST FILE (in the Class-Path section)

../ prop_dir / prop1.properties ../ prop_dir / prop1.properties

../prop_dir/prop1.properties ../prop_dir/prop1.properties

但它们都不起作用。

运行目录的体系结构如下

The architecture of the running dir is the following

+
+ MyRunnableJar.jar
+ prop_dir/
   + prop1.properties
   + prop2.properties

非常感谢

丹尼尔

编辑

当我执行以下行时

System.out.println(System.getProperty("java.class.path"));

我在控制台中获取

MyRunnableJar.jar


推荐答案

为了解决这个问题,我使用了一种解决方法:我没有运行可运行的jar,而是运行主类,而是将jar添加到类路径中。

In order to solve this problem i used a workaround: instead of running the runnable jar i runned the main class and I added the jar to the classpath.

我使用的命令如下:

java -classpath .;MyRunnableJar.jar;prop_dir; my.package.MyClass

这篇关于添加属性文件以构建可运行jar的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆