Is it possible in Java read files placed in a Jar that it's placed in a Ear too?

From the ear file you should be able to extract the jar file. Then you can use WinZip 7 Zip etc to do explore the jar file contents the GUI. Or you can run the jar tf command to extract the content of the jar file in command line.

If you don't have any of these tools and using windows, then you can rename the jar file to a . Zip and windows should be able to explore it (most of the cases it works).

Up vote -1 down vote favorite share g+ share fb share tw.

I was wondering if is possible to find the content in an XML file placed in a jar thath is placed in a ear too. It would help me find the properties of java beans. Up into the ear I can iterate through documents and see what's inside, but if it is a jar I can't iterate documents inside that.

Someone can give me some advice? Java java-ee jar link|improve this question edited Nov 17 '10 at 9:54 asked Nov 15 '10 at 18:32Dario18629 100% accept rate.

The question title contradicts the question message. The answer to question title is "no", the answer to question message is "yes". Detailed advice depends on the context which is entirely unclear.

"scroll through documents" makes no sense. What exactly is the functional requirement and use case? – BalusC Nov 15 '10 at 18:36 I assumed he has a jar file packaged in a ear file.

But you are right BalusC, the title contradicts the question. I didn't notice that. – CoolBeans Nov 15 '10 at 18:39 @CoolBeans: so, you interpreted "scroll through documents" as "using Windows explorer to view files in EAR/JAR"?

This isn't a programming question at all and the title starts with "Is it possible in Java" ... – BalusC Nov 15 '10 at 18:41 Oh, did he mean to extract a jar file programatically like using java.util.jar. JarFile? – CoolBeans Nov 15 '10 at 18:43 @CoolBeans: I don't know.

This question is definitely unclear and not useful. – BalusC Nov 15 '10 at 18:46.

From the ear file you should be able to extract the jar file. Then you can use WinZip, 7 Zip, etc to do explore the jar file contents the GUI. Or you can run the jar tf command to extract the content of the jar file in command line.

If you don't have any of these tools and using windows, then you can rename the jar file to a . Zip and windows should be able to explore it (most of the cases it works). Edits - I am not sure if you wanted to do it using Java.

In that case you are looking for JarFile. I found an example of it here for exploring Jar contents programatically.

I think the OP wants to do this programmatically. – anirvan Nov 15 '10 at 18:44.

So I just tested the thing you want to do - and as long as the JAR lies in the classpath of your EAR, then you can access any file within it. Basically the try to look up the file from the context-root of your application. For example if in your JAR the file abc.

Xml resides under the package a.b. Resources, then from say a servlet in your EAR you can access it using : InputStream is = this.getClass().getClassLoader(). GetResourceAsStream("a/b/resources/abc.

Properties").

Abc. Xml! = abc.

Properties, plus it's in multi-classloader environments more recommended to use the thread context's classloader rather than the class' one. – BalusC Nov 15 '10 at 18:56 agree on the multi-classloader env part, but the . Properties was a typo.

– anirvan Nov 15 '10 at 20:47.

Yes, you can read any file that is packed into zip file. It does not matter how many nested zip file you have to open on your way. Use ZipInputStream, get needed ZipEntry, read it content.

If it is still zip, open it and do it again and again until you access the required resource.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions