Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



XML file in a jar

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-03-2010
Member
 
Join Date: Dec 2009
Posts: 213
XML file in a jar

Hello,
I have an application that reads an XML file for configuration, when I run my application from Eclipse, I have no problem, and when I run my application from a jar, it does not find the file. Do you have any solution for this. Is that the eclipse is an IDE that is why the only it can execute the file. Any help on this is appreciated. Thanks in advance.
Reply With Quote
  #2  
Old 09-03-2010
Member
 
Join Date: Nov 2009
Posts: 447
Re: XML file in a jar

Hello,
The Class File represent files available on the local system, but can in no way represent remote files or files within the archive as in your case. If you just want to read the file you have in any case need to use File. You have to directly use the InputStream'sURL or Method getResourceAsStream (). I hope you are getting the point what I am trying to explain here. If you have more queries then you can ask.
Reply With Quote
  #3  
Old 09-03-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: XML file in a jar

Hello,
All depends what you want to file.
Code:
getClass (). getResource ( "configuration.xml") returns the URL of the file.
Your problem is probably the new File (.. ToFile ());
I think should try the following part of the code
Code:
File fl = new File(getClass().getResource("configuration.xml").tr());
Reply With Quote
  #4  
Old 09-03-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: XML file in a jar

Hello,
I have about a similar problem except that I can read the XML file that is in my JAR By cons I would like to edit.
Code:
XMLWriter w = new XMLWriter(new FileWriter(getClass().getResource("/ hibernate.cfg.xml").function toString() {
    [native code]
}, false));
w.write( "XML feed as Document.class");
w.close();
It makes me an error saying that the path does not exist.
Code:
Reading the XML -> OK
Writing XML -> not OK
Reply With Quote
  #5  
Old 09-03-2010
Member
 
Join Date: Nov 2009
Posts: 347
Re: XML file in a jar

Hello,
I do not know what exactly you want in your code, but i have a code with me, see if this helps you.
Here the code
Code:
File t = new File ("t");
t.mkdirs();
Process proc = new ProcessBuilder ("pjr", "-xf", "myjar.pjr", t.getName ()).start();
proc.waitFor();
// TODO read and update persistence.xml
Process pjr = new ProcessBuilder ("pjr", "-cf", "myjar.pjr", t.getName()).start();
pjr.waitFor();
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "XML file in a jar"
Thread Thread Starter Forum Replies Last Post
I cannot file “Confirm open after Download" checkbox for file types in Windows 7 Dalapathi Operating Systems 4 07-02-2011 10:19 AM
Dead space 2 error while installation "Source file not found: (file destination)...Verify that file exists Ucchal Video Games 3 28-01-2011 06:26 AM
Encrypting File System (EFS) encrypted file data corrupt after shutdown and restart Abhik Windows Software 5 13-08-2010 12:36 AM
How can i make .cab file and would like to add file to an existing cab file Kamran Operating Systems 3 16-07-2009 02:29 PM
Content file download failed. Reason: File cert verification failure skharoon Server Update Service 4 06-06-2009 03:13 AM


All times are GMT +5.5. The time now is 11:09 AM.