• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get an xml file that exists in jar  RSS feed

 
chibi riko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to get an xml file that exists in jar
Capture-d-cran-2016-10-25-20.06.15.png
[Thumbnail for Capture-d-cran-2016-10-25-20.06.15.png]
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can use the "jar tf" command to list the contents of the jar file. I believe the directory is also listed with the name of the files.

Henry
 
chibi riko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I know, but how I should read this file from jar
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chibi riko wrote:yes I know, but how I should read this file from jar


If the jar file is in your classpath, then you can use the class loader to fetch it. See the getResourceAsStream() method of the Class class.

Henry
 
Leoncio Thiago
Greenhorn
Posts: 11
Eclipse IDE Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chibi riko wrote:how to get an xml file that exists in jar



You can get what you want(working example code) in this blog page:

http://phonecoding.com/2016/08/how-to-read-xml-file-from-jar-in-java.html


please, let me know if it helps you.

Thiago
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no need to reinvent the wheel. getResourceAsStream() does exactly what the OP wants, and extracting archives is needlessly complicated.
 
chibi riko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all, I found the solution , getResource () that allows you to access a resource that exists in jar .
 
chibi riko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
chibi riko wrote:yes I know, but how I should read this file from jar


If the jar file is in your classpath, then you can use the class loader to fetch it. See the getResourceAsStream() method of the Class class.

Henry

thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!