Trying to get a properties file from a jar file in another jar file
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);
it fails to find the properties file contained in B.jar. The code works when run in Eclipse, so I kn开发者_C百科ow the correct properties files are there.
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
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,
Greg
I'd also recommend working around nested jars. I usually just do this in my build.xml to build one jar with all the libraries unpacked into it:
<target name="fatjar" depends="compile">
<jar destfile="${isamjar}" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="com.xyz.Main"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="./bin"/>
<fileset dir="." includes="src/**"/>
<zipfileset excludes="META-INF/*.SF" src="${l}/derby.jar"/>
<zipfileset excludes="META-INF/*.SF" src="${l}/jconn3.jar"/>
<zipfileset excludes="META-INF/*.SF" src="${l}/log4j-1.2.9.jar"/>
<zipfileset excludes="META-INF/*.SF" src="${l}/${jar4j}"/>
</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.
精彩评论