尝试从另一个jar文件中的jar文件获取属性文件 [英] Trying to get a properties file from a jar file in another jar file

查看:61
本文介绍了尝试从另一个jar文件中的jar文件获取属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Eclipse构建的可执行jar文件(A.jar),它依赖于jar文件中包含的其他jar文件(B.jar),并可以通过jarinjarloader访问.虽然这样做可以访问这些jar文件中的Java代码,但是当该代码调用时

I have an executable jar file (A.jar), built with Eclipse, that relies on other jar files (B.jar) that are included in the jar file, and accessed via the jarinjarloader. While this works to access the java code inside those jar files, when that code calls

InputStream inStream = <Class>.getClassLoader().getResourceAsStream(propFile);

它无法找到B.jar中包含的属性文件.该代码在Eclipse中运行时有效,因此我知道其中包含正确的属性文件.

it fails to find the properties file contained in B.jar. The code works when run in Eclipse, so I know the correct properties files are there.

我尝试提取A.jar,然后提取B.jar,然后压缩合并的文件,但这不起作用.查看清单文件,Main-Class是org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

I tried extracting A.jar, then extracting B.jar, and then zipping up the combined files, but this does not work. Looking at the Manifest file, the Main-Class is org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

我可以对清单文件进行一些更改(例如,在Rsrc-Class-Path中添加一些内容)来使它起作用吗? Rsrc-Class-Path已经包含"./",但这显然不是让属性加载器查看我的属性文件.

Is there some change I can make to the Manifest file (say, adding something to Rsrc-Class-Path) that will get this to work? Rsrc-Class-Path includes "./" already, but that clearly isn't letting the properties loader see my properties files.

TIA,

格雷格

推荐答案

原来Eclipse有一个我错过的设置. 导出"可运行的JAR文件"时,您可以选择"将所需的库提取到生成的JAR ".虽然这可能会带来一些许可证问题(取决于您要合并的JAR),但在我的情况下,它就像一个魅力一样,给了我一个(较小,因为我在各个jar文件中有很多重复项)包括)实际起作用的罐子.

Turns out Eclipse has a setting I missed. When Exporting a "Runnable JAR File" you can select "Extract required libraries into generated JAR". while this may give some license issues (depending upon the JARs you're merging in), in my case it worked like a charm, giving me a single (smaller, since there were a lot of duplicates among the various jar files I'd been including) jar that actually worked.

这篇关于尝试从另一个jar文件中的jar文件获取属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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