• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read a file from Jar/EAR ?  RSS feed

 
Prashant Saraf
Ranch Hand
Posts: 57
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My application is based on weblogic 9, we are creating EAR, i want to read a file from same package of that ear. but it always gives file not found exception. please help.
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you trying to read the file?
If a JAR is in the classpath, you should be able to open it with Class.getResource(String name) or Class.getResourceAsStream(String name)
You can also read a file from a JAR/EAR/WAR with a particular URL:

Where the first part is the path to the jar file, a '!', then the path within the JAR. See this example.
 
Prashant Saraf
Ranch Hand
Posts: 57
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have my Java file and the files i want to read xml and jpeg files are in same package. And it part of EAR going to deploy on weblogic 9.2.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!