Editing xml file inside a Jar
Hello ,
After creating my desktop application i created a Jar for it, but when i tried to change my program settings through the jar(Which is set in an xml file), i found that the changes did not happen.
After some search i found that i can only edit files in a Jar by re-creating the jar again.
Sure there's another easier way ? .... This is a normal demand.
If not then what's the best way to deliver my program to my clients ?
Thanks ,
Hesham
pbrockway2 wrote:
i found that i can only edit files in a Jar by re-creating the jar again.That's correct.
You could consider using the [Preferences API|http://java.sun.com/javase/6/docs/technotes/guides/preferences/index.html] to store program settings.
... or put the altered config in an external XML file. You could still keep a default config XML in the jar.
Similar Messages
-
Updating an XML file inside the Jar executable
Hello all!
I would like to ask how can i update an XML file that is packaged inside my jar file?
For intstance:
I have a Java Application in NetBeans
Inside a package i have constructed a custom .xml file.
I can read from this file using
.....getClass().getResourceAsStream("/.../file.xml")and after that using XPath for querying and works fine.
I want to update an entry in my xml file so the jar contains now the newly updated file.
Thanks everyone who spends his time to read this. Hope someone can help me.Even if it were possible, it would be a bad idea. A jar file is something you deploy. It can be really hard to manage ongoing maintenance if the thing you deploy changes after you've deployed it.
Just create a file, in an appropriate place given the user's OS, to hold data that changes after the jar has been deployed. Your application will still be in a single jar; it's just that the application will happen to create additional content outside the jar. -
Validating xml-files inside jar-files for JWS
I want to use xml-files inside a jar-file and want to validate them with dtd-files,
located in the same jar-file. This does work, but only as long as the dtd-file is
in the same directory as the xml-file.
For example, I have no problem, with a DOC Type-statement like
<!DOCTYPE questestinterop SYSTEM "ims_qtiv1p1.dtd" >
With this statement, however, one needs an approprate dtd in every directory containing an XML-file of that type.
If however i want to gather the necessary dtd's in a directory one (or more) levels above with a DOCTYPE-statement of the form
<!DOCTYPE questestinterop SYSTEM "../ims_qtiv1p1.dtd" >
I get error messages of the form
java.io.FileNotFoundException: JAR entry Mikro/Marshall/BookQuestions/../ims_qtiv1p1.dtd not found in C:\Dokumente und Einstellungen\wreiss\Anwendungsdaten\Sun\Java\Deployment\javaws\cache\http\Dwiwi.upb.de\P80\DM~vwl08\DMOViSS\DMoviss_current\RMMikro.jar
at org.apache.crimson.parser.Parser2.fatal(Unknown Source)
at org.apache.crimson.parser.Parser2.externalParameterEntity(Unknown Source)
at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Unknown Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
at org.apache.crimson.parser.Parser2.parse(Unknown Source)
at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at oviss.competenceCenter.XMLExpert.setElements(XMLExpert.java:245)
though the dtd-file is in the parent-directory (inside the jar) and the unpacked xml-file can be successfully validated.
Why does this happen. How can one use a single dtd for multiple xml-files (of the same type) in different directories?.
Thanks
Winfried ReissIn reply to myself, replacing the HTMLBrowser constructor with this;
public HTMLBrowser()
URL url;
try
// Construct the URL
url= this.getClass().getResource('/'+dir+'/'+startPage);
setPage(url);
catch (Exception e)
System.out.println( "Problem setting help homepage");
setEditable(false);
addHyperlinkListener(new LinkListener(this));
}made it work. This is because seemingly you need '/' at the start of the resouce's path and '/' as the separator, regardless of platform.
I hope this helps someone else.
John -
Updating an XML file inside the executable JAR.
Hello all!
I would like to askk how can i update an XML file that is packaged inside my jar file?
For intstance:
I have a Java Application in NetBeans
Inside a package i have constructed a custom .xml file.
I can read from this file using
.....getClass().getResourceAsStream("/.../file.xml")and after that using XPath for querying and works fine.
I want to update an entry in my xml file so the jar contains now the newly updated file.
Thanks everyone who spends hit time to read this. Hope someone can help me.Please don't cross-post:
http://forums.sun.com/thread.jspa?threadID=5342194 -
Reading an xml file from a jar file
Short question:
Is it possible to read an xml file from a jar file when the dtd is
placed inside the jar file? I am using jdom (SAXBuilder) and the default
sax parser which comes with it.
Long Question:
I am trying to create an enterprise archive file on Weblogic 6.1. We
have a framework that is similar to the struts framework which uses it's
own configuration files
I could place the dtd files outside the jar ear file and specify the
absolute path in an environment variable in web.xml which is
configurable through the admin console.
But I want to avoid this step and specify a relative path within the jar
file.
I have tried to use a class which implements the entityresolver as well
as try to extend the saxparser and set the entity resolver within this
class explicitly, but I always seem to sun into problems like:
The setEntityresolver method does not get called or there is a
classloader problem. i.e. JDOM complains that it cannot load My custom
parser which is part of the application
VijayPlease contact the main BEA Support team [email protected]
They will need to check with product support to determine
the interoperatablity of Weblogic Server with these other
products. -
Reading external xml files from a jar
Hi,
I am trying to read an xml file from a jar (which is not present inside the jar ) .
I am passing the file name as a string (like C:/folder/filename) to the SAXBuilder but it throwing
unknown protocol: c error.
i tried using an url , tried using a relative path but to no use.
Need help in this regard urgently.
TIA,
Regards,
HarshaHi,
Actually, my application needs to read two xml files , parse it, perform some operation and write
the result to an output file.
The names of the two xml files i mentioned, are specified in a properties file as absolute paths. (I even tried converting them to URIs)
The xml files are in the same directory as the jar ( i dont know if it should matter as i am giving the absolute path).
The main class reads the names of the files and passes the names as strings to the SAXBuilder.
This is where i am getting an exception.
Going by what you said, is it not possible for a java class to read a fie outside of the jar ? Is there no way to do this ? And right now i am not sure of how to go about this or if there's any work around . Any help would be appreciated.
Kindly reply at the earliest
TIA,
Harsha -
Include and call an .exe file inside my jar file
Hi.
I want to include an exe file and call it inside my jar file. this is the code.
InputStream is = getClass().getResourceAsStream("/native/my.exe");
int[] line = new int[is.available()];
File myFile = File.createTempFile("my","exe");
myFile.deleteOnExit();
myFile.setExecutable(true);
FileOutputStream out = new FileOutputStream(myFile.getAbsolutePath());
int i = 0;
int c;
while((c=is.read()) != -1){
line=c;
i++;
is.close();
for(int j= 0;j<line.length;j++)
out.write(line[j]);
out.close();
So i store it in my temp folder. Than i run
String myFileLocation = myFile.getAbsolutePath();
p = rt.exec(myFileLocation);
Everything goes fine, but the behaviour of the .exe file is not the same. I mean when i run the commands
PrintWriter writer = new PrintWriter(p.getoutputStream());
writer.println("command");
the behaviour is not the same. What goes wrong.But to load the xml file I need to create a File objectIf this is true then you will not be able to load the XML file, since a jar entry is not a File object and cannot be represented as one.
However if you get rid of whatever it is that loads your XML file and replace it by more standard JAXP processing, you should be able to parse an InputStream that reads from the jar entry. You know how to get that so it should not be a problem. -
How to read some files inside the jar
Hi,
I have an applet that runs with JWS. The user can input some information and then I need to show this information in a web page. As the application can be run offline, I cannnot use JSP�s to generate the web page. The information is saved in a xml file, so I use a xsl parser to generate the html code. The problem is that I have to include some javascript files (.js). I put these files inside the jar, but, how can I read these files, or how can I reference these files from inside the html page ?
Thanks !You can use getClass().getResource(classpath)
to get a stream version of the data from your
jar file. If you need to put it in a file, you
can write that stream to a file in a temp directory.
classpath is the classpath of your js file -
How to access XML files inside IDML?
Hi All,
How to access the different XML files like designmap, story, masterspread, etc. found inside the IDML files?
Pl. help.
Thanks,
PraveenAn External Library DC is only intended to include jars. Using a Java DC may be a better idea, unless you put your xml files into a jar first (but you'd need a Java DC for that...).
-
Extracting and updating files inside a JAR file... from my code
Hi.
I need some help in the following:
from my code, I need to search a JAR file, open it, unzipped it, then I need to search a xml and property files inside the JAR, after that I need to modify the files and finally, my code has to save the changes and update the JAR file. All that must be from my java code.
How can I do that? I am trying to use Runtime.getRunTime().exec().... but I am not sure that it works. Besides, I don�t know what command to include in the exec() method. Is there any way to do that?
ThanksThe normal reason I see for this requirement is that people want to update a properties or data file. The approach I use it that I first look for the data file in a well defined location and if I find it I use it and update it as required. If I don't fine it I create it base on a template file read from the jar file using getResourceAsSrream().
In this way I never have to update the jar file. -
Running a batch file inside a jar
HI all
I created a jar file , in which i need to run a batch file , so i wrote a main class to execute the run the batch file , but when iam running the jar it is searching for the given batch file out side the jar.
my code is some thing like below
public static void main(String args[])
try
Runtime rt=Runtime.getRuntime();
Process process=rt.exec("%DIRNAME%/start.bat");
InputStreamReader reader =
new InputStreamReader ( process.getInputStream () );
BufferedReader buf_reader =
new BufferedReader ( reader );
String line;
while ((line = buf_reader.readLine ()) != null)
System.out.println (line);
catch (IOException e) {
System.out.println (e);
}so please help me.. is it the problem in specifing the path...?
are does it have any other method to read the stream functions ..
thanks in advance
samI don't think this will work. You could not go to a command line and enter, "%DIRNAME%/start.bat" if start.bat was inside a jar - the CLI doesn't know how to read a batch file inside a jar.
I think it would work to programmatically read the lines of start.bat (when it is inside the jar) into an array of Strings and use Runtime.exec with the array as the argument.
It would also work to extract the start.bat file, then execute it using Runtime.exec. -
how to edit xml file particular value. and how to send xml file over ip address 192.168.2.10 device using ftp through Ethernet
Hello
For using FTP function in LabVIEW, I recommend you to check this document: FTP Basics
Also, take a look at FTP Browser.vi, which is available at the Example Finder.
To edit a XML file, try to use VIs in XML palette. Maybe Write to XML.vi helps you.
Post your current VI if possible.
Regards
Mondoni -
Java Files inside the jar file cannot be read or accessed through Eclpse
The Java File inside the jar file of the eclipse cannot be accessed through the Eclipse . It shows error for the modules in the jar file .
But when compiled with adding the jar files to the class path the compilation is successful .
How can i browse through the files in the jar like going into the function definition .
TIA ,
ImranOpen MPlayer OSX and show the playlist (command-shift-p) then drag the file into the playlist. Click the file in the playlist and click the "i"nfo button. What does it list for file, video and audio format?
Not all of the codecs used in avi and wmv files are available for OS X so I'm guessing your file happens to be using one that isn't... -
Changing values in property file inside a jar in an ear
Hi,
I have an application that contains EJB. The environment values needed for initial context of the ejb is kept in a .properties file. I have created an ear of the application. Inside the ear there is a jar which contains the .properties file. I need to deploy the ear to different environments. However before deploying I need some kind of script to change the values in the .properties file inside the jar in the ear.
Can anyone provide some help/pointers about how can I achieve it (Using ANT/WLST)WLST does not have any capability to update a JAR.
WLS 10.3 (still in tech preview) has the ability to override properties
files inside the jar with an external properties file. This would allow you
to deploy the same ear to different environments, and then only deploy a
different properties file in the plan directory.
<Rishi Shah> wrote in message news:[email protected]..
Hi,
I have an application that contains EJB. The environment values needed for
initial context of the ejb is kept in a .properties file. I have created an
ear of the application. Inside the ear there is a jar which contains the
.properties file. I need to deploy the ear to different environments.
However before deploying I need some kind of script to change the values in
the .properties file inside the jar in the ear.
Can anyone provide some help/pointers about how can I achieve it (Using
ANT/WLST) -
I am having Html help files inside my Jar file
Dear Friends;
i am having Html help files inside my Jar file.
how will open the html file using Java Help.
Thank uhttp://java.sun.com/products/javahelp/reference/docs/index.html
Maybe you are looking for
-
WHAT is happening with Firefox?????
I have had NOTHING but problems/issues with Firefox in the last week. One day all my tabs disappeared. Support had me start another profile. Two days later all my bookmarks disappeared. The next day I can't print ANYTHING from American Greetings. Tod
-
Moving music files via external hard drive-- Can you keep ratings/playlists
I keep all my music on an external hard drive in order to prevent it getting lost. Anyways... what I'm wondering is if I go to move my music from one computer (comp. A) to another computer (comp. B), is it possible to keep all the ratings and my play
-
i want to change my id password , but unfortunatley i lost my alternate id password now he send infor tho that id n i also dont remember my secret questions so plz help me how i get back my id , as i m recieving mags from apple that someone using my
-
Restoring files from dvd+r
quite simply I had to recover my computer using the recovery discs.Before doing so I backed up my pics docs and software onto dvd+r.Now I want to restore this software into the relevant places but Windows will not let me open the programs that are st
-
Yahoo Music Engine can't recognize Zen Mi
Is there any definiti've guide out there to get the Zen micro working with the Yahoo subscription service? When I plug in my Zen, WinXP recognizes it and asks me what I want to do (i.e. synch, or take no action), but neither the WMP software nor Yaho