I have a helper class I18nthat can find one available Localeby looking at the file name inside the Jar application.
private static void addLocalesFromJar(List<Locale> locales) throws IOException {
ProtectionDomain domain = I18n.class.getProtectionDomain();
CodeSource src = domain.getCodeSource();
URL url = src.getLocation();
JarInputStream jar = new JarInputStream(url.openStream());
while (true) {
JarEntry entry = jar.getNextJarEntry();
if (entry == null) {
break;
}
String name = entry.getName();
}
}
Currently this does not work - jar.getNextJarEntry()always returns null. I donβt know why this is happening, all I know is what is urlinstalled on rsrc:./. I have never seen this protocol and could not find anything.
Curiously, this works:
class Main {
public static void main(String[] args) {
URL url = Main.class.getProtectionDomain().getCodeSource().getLocation();
JarInputStream jar = new JarInputStream(url.openStream());
while (true) {
JarEntry entry = jar.getNextJarEntry();
if (entry == null) {
break;
}
System.out.println(entry.getName());
}
}
}
In this version, although there is practically no difference between them, it is urlcorrectly set to the path to the Jar file.
Why does the first version not work and what violates it?
UPDATE
, Eclipse . NetBeans, Eclipse URL- rsrc:./.
Package required libraries into generated JAR, Eclipse jarinjarloader Jar, . , ?
, . , , ?