Getting List of Files Within Jar
Ok, so I need to do something that, in theory, should be easy, but I haven't found anything useful online.
I will have an executable jar. When that jar is executed (via the main .class file inside of it), I need to be able to get a list of the files inside that jar.
The reason I am having problems finding a solution online for this is because the all of the solutions that are sort of about this assume at least one of two things:
1) The jar name will never change
2) The jar directory will never change
That is not that case for my situation. I know, for a fact, that the jar directly will change AND I would assume the jar name will also eventually change. Because of that, I need to be able to access the jar without using the directory referencing.
Essentially, I am trying to get the list of all of the .class files in the jar that is being executed so I use the get stream of the file, provided it meets certain naming criteria. The files will not be in any directories inside the jar.
Can anyone help me out here? This has been an issue for me for like 2 weeks now and I have no idea where to start.
Re: Getting List of Files Within Jar
Ok, well naturally I just happen to figure it out as soon as I posted the question.
Here is the code for anyone in the future who has this same issue:
Code java:
//Where "CreatingJar" is the name of the class this group of code is inside of
JarInputStream in = new JarInputStream(CreatingJar.class.getProtectionDomain().getCodeSource().getLocation().toURI().toURL().openStream());
JarEntry entry = in.getNextJarEntry();
ArrayList<String> entryList = new ArrayList<String>();
while(entry!=null)
{
entryList.add(entry.toString());
entry = in.getNextJarEntry();
}
in.close();
Enjoy