How to access a xml file stored in a jar file

Hi all,
We have a java web start app that uses the jasper reports libraries to produce pdf reports. When running and testing from the ide the prog works ok. However when we place the jar on the web server and run the web start app the prog complains "the system cannot find the file specified".
The xml files are stored in the jar under a directory called reports. The code access the files like so. (We are temporarily writing the output file to c drive.)
JasperCompileManager.compileReportToFile("reports\\airexportagy.xml","c:\\airexportagy.jasper");
IS there a different way one is supposed to access these resources from a jar file using web start?
THanks

Always (well, almost always anyway) access resource files thru the classloader. Example:
InputStream xmlStream = getClass().getResourceAsStream("/myresource.xml");
This will find "myresource.xml" in the classpath. If you omit the "/" part, it will still attempt to find that file in the classpath, but expect to find it within the same directory hierarchy as the calling class (its package hierarchy).

Similar Messages

  • How to use schema files stored in a jar file

    I am in a great trouble in accessing the schema files in the jar file. I have to validate my xml files against those schema files while parsing the xml file. I am unable to get the path of the schema files.
    I am getting the path as
    E:/ConfigUtility/schemas.jar!/Schema.xsd
    which is not a valid path name for windows. Plese help me and send me some code how to access a schema file that is in the jar file.
    thanks and regards,
    Krishna.

    Run the program from command line, this way you will see the errors, if any.
    example.: java -jar theJarfile.jar
    I was successful in creating a comm application. I placed the win32com.dll in the same directory of my application jar file and all worked.
    I also extracted the comm.jar , and jar'd my app with the extracted comm files to make one jar.
    I also had a fileWriter() to get the clients jre path and my app would write the javax.properties file to the correct place.
    It took me severel weeks and late nights to accomplish this, but it was all necessary to be able to install only my app, and not a bunch of api's that were needed.

  • In a JSP how can access an XML where the XML is present in JAR file in the

    All,
    The Requirement is as below,
    I have a JSP LaunchMe.jsp, and I have a jar utils.jar. both are present in my deployable war file.
    And I have an XML Details.XML present in the utils.jar file.
    Here I want to access Details.xml in the LaunchMe.jsp.
    Can any one please let me know how can I do this.
    Thanks,
    Subramanyam V

    Yes. You have to understand that to read a FILE (one that is seen as a file by your OS), you probably use a FileInputStream, which is a special case of InputStream. When the 'file' is not a FILE anymore, but an entry in a jar (the OS does not see it, only utilities like WinZip or jar see it), you cannot use a FileInputStream, but some other InputStream. Which one? The one returned by getResourceAsStream(), whatever this is (you don't really care). And all the rest will nicely fall into place.

  • Load a file stored in a Jar Archive

    Dear all,
    I have a text file stored in a Jar Archive and I want to obtain a File instance of the text file from the jar file. The reason for this is because I have a method which read in a File instance of the file.
    From my understanding, one can obtain an byte[] array from a file stored in a text file. Is there a way to convert the byte[] into a File instance?
    Thanks.
    Sunny

    Once again, thank you for your prompt response. I agree that one can obtain an inputstream of a file from the Jar archive and work with it. The problem that I am having is that the method that I have is not written by me, to be precise, I am using Syslog and try to read in a configuration file packed in a Jar Archive. The Syslog library only provide a method, which only accept a 'File' instance as an input argument.
    Thanks.
    Sunny

  • Including a jar file inside an executable jar file

    Is it possible to include a jar file inside another (executable) jar file such that the included file is part of the class path for the outer file? If so, how do you specify this in the classpath in the manifest?

    Russ_Bjork wrote:
    Is it possible to include a jar file inside another (executable) jar file such that the included file is part of the class path for the outer file?No. Actually, I suppose it would be possible if you do all the 'heavy lifting', but Java is not designed to handle Jars within Jars.
    What do you see as the advantage of doing that?
    Is your app. a rich client (e.g. Swing, AWT, SWT..)?
    Can you distribute the app. from a server or the internet?

  • Creating jar file including 2 another jar files

    hi
    My project has java files, properties files,batch files as well as two jar files,mail.jar & activation.jar(for importing packages).
    I have to include these jar files while setting environment variables.
    Now i want to make "MyPrj.jar" file for myproject ,can anyone pls help me how to include these all files into a single jar file. and how to make setup file
    I have tried to extract out .class files of mail.jar & activation.jar & i ve created MyPrj.jar by including all class files(including class files of mail.jar & activation.jar) but manifest file(headers) are not added to MyPrj.jar.
    i have also tried to give mail.jar & activation.jar in Class-Path of menifest file, but it is also not working.
    Pls Help
    Thanks a lot

    [http://sourceforge.net/projects/one-jar]
    "One-JAR(TM) is a simple solution to a vexing problem in Java: how to distribute an application as a single jar-file, when it depends on multiple other jar-files. One-JAR uses a custom classloader to discover library jar files inside the main jar. "

  • Compress two .jar file into a new .jar file

    Hi all, i would like to ask it there anyone know how to compress two or more .jar file into one new .jar file?
    because i'm currently need to engage with one big project which have to add 34 .jar file into JCreator, so that the relevant classes can be found when compile the code.
    another question is, what is the maximum archive can be add into JCreator? is it limited or unlimited?
    So, any idea from you all?
    Regards,
    poh_cc

    You should probably ask the authors of JCreator about the limitations of it.
    The classloader can't read jars from jars and I would advice against extracting all jars and jar all classes into one big fat jar.
    Kaj

  • Quick file insert into large jar files

    I'm looking for a quick way to replace a single class file within a large JAR file (5mb or more). I know you can use jar -u but this searches the whole file before inserting my new class which is just as slow as making the JAR file from scratch.
    Due to existing development constraints I cannot split up the JAR or unpack it as it would stop the rest of the application from working. Currently it takes several minutes to compile and deploy to the server making small changes to the code a right pain.

    jar -u is the quick way, :) but maybe using WinZip might be an alternative for you?

  • How do I load property files and images stored in the jar file?

    Hi
    So, if I have a structure like this:
    /com.myfirm.myproject.SomeClass
    /images/
    /properties/
    And I pack this structure into a jar file, how do I then access the images under "/images/" and the property files under "/properties/"? A link to a good tutorial on this would be perfect, or a description/hint/howto :)

    Im having problems even loading direcly from the directory..? I have this structure:
    src (source dir)
    classes (classes dir)
    lang/textRb_en_US.properties (the file I want to load)
    Then I have this code:
    Locale currentLocale = new Locale("en", "US");
    ResourceBundle textRb = ResourceBundle.getBundle("/lang/textRb", currentLocale);But it gives me a "java.util.MissingResourceException: Can't find bundle for base name /lang/textRb, locale en_US". I start my application from within Eclipse, and I have tried to move "lang/textRb_en_US.properties" into the classes dir, but same error.
    Im confused as to there Java looks for ressources, and I need this to work no matter where I put my classes/jar. Could you help me out here?

  • How to compress a bunch of .java files into a single .jar file?

    Hello everyone! I am working on a Chinese segmentation job. Someone offers very excellent
    such tool. When I copy his example, I find it imports
              import org.apache.lucene.analysis.Analyzer;
              import org.apache.lucene.analysis.Token;
              import org.apache.lucene.analysis.TokenStream;
              import org.mira.lucene.analysis.IK_CAnalyzer;I have downloaded IK_CAnalyzer.jar file which contains org.mira.lucene.analysis.IK_CAnalyzer class.
    I find that I need to download lucene, thus I went into the following website
    http://lucene.apache.org/#06+May+2008+-+Lucene+Java+2.3.2+availableand downloaded the lucene-2.3.2-src.tar.gz. Aftre unzip, I found all java source files in java directory (and in many other different subdirectories). Now it seems I need to compile all the src files and compress them into a single .jar file while keeping their original hierarchy unchanged
    I think I should use jar command and with some additional options.
    Can anyone show me how to do that?
    Many thanks!
    Edited by: aaron9979215 on Jul 12, 2008 5:17 AM

    Thanks for reply, I?ve read that tutorial before I post. Howevver, it do tells how to compress a jar file.
    The question I have is how to compile two .java file stored in different packages like
    rootPackage-->subPackage-->a.java
    rootPackage-->subPackage2-->b.java
    I want to compile a,java and b.java both and keep their hierarchy like rootPackage.subPackage.a unchanged. If I directly go into subPackage and compile a.java, I think the hierarchy is changed.
    What do you think about it?

  • Accessing a Derby database inside of a Jar file...

    Hello,
    I've browsed many threads that touch on aspects of this topic, but I still can't seem to figure this out. Here is my dilemma:
    [1] I have a simple application that stores some data using JavaDB.
    [2] Everything works fine when I bundle the app into a jar, as long as I leave my Database folder outside the jar
    [3] If I include the DB in the jar the app does not see it.
    [4] I can't just leave the folder outside the jar because I eventually plan on deploying the app as a Web Start program.
    The Dev guide on JavaDB says +"A database can be in one of many locations: in the current working directory, on the classpath, in a JAR file..."+, and this apparently can be set using the derby.system.home property. I currently use the following to set this property: System.setProperty("derby.system.home", ".myDatabase"); How would I need to change this to allow the app to find the database inside the jar? If this requires the DB to be read-only (which is fine with me), what properties need to be set to designate the DB as such?
    Any input would be greatly appreciated.

    Well, upon rereading the Derby Developer's Guide I found the information I sought in the section "Creating Derby databases for read-only use" (p.34-37). I'm still not 100% sure about how to do the Web Start implementation, but this should put me on the right track.
    [UPDATE IN CASE ANYONE STUMBLES UPON THIS THREAD] It seems that the issue with Web Start is that the database needs to be access a writable location for the temporary directory, so I presume web start would have to request disc-access privileges... something I'm trying to avoid.
    Edited by: CommanderSalamander on Nov 9, 2007 10:06 AM

  • How to get the com.sap.portal.admin.wizardframework_api.jar file

    Hi this is related to the wizard creating component required .jar file. Can any body tell me , how to get this jar file. I have searched in my IDE plug-in's folder. But i have nt find this.
    com.sap.portal.admin.wizardframework_api.jar
    how to get thid jar file.
    REgards
    Vijay

    Vijay,
    You can access the above mentioned par file from this location,
    System Admin -> support -> Support Desk->ROOT/WEB-INF/deployment/pcd (download this folder)
    ->com.sap.portal.admin.wizardframework.par.bak->extract the file
    alternatively,
    u can find the same in,
    \j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps\com.sap.portal.admin.wizardframework\lib
    Thanks & Regards,
    Ramganesan K
    Keane Inc

  • How to retrieve constants value from compiled code in jar file?

    Hi everyone,
    I've been looking for a way to solve this for a week now, without any much success... and I've finally decided to ask the Java gurus for a solution! :-)
    Here's what I am basically trying to do:
    I have several jar files in which there are only compiled code (.class).
    In every class, there are 2 constants (declared as static final String) that I would like to retrieve (one is the version and the other the date of the last modification).
    My goal is to print a list of all the classes in the jar files with the values of these 2 constants for each class.
    The solution that I have right now to do this does not work properly: for now, I read all the elements of the classpath, check if these are jar files, and if so, I look into each one and load all the classes one by one and print the results.
    The problem with this is that it uses the method Class.forName(className) and as some classes are unfortunately present in many jar files (2 or 3 copies), once the classes have been loaded, then it won't be "reloaded".
    Without the possibility to "reload" these classes, I cannot see inconsistencies in the versions of the classes present in the jar files.
    I have read many articles, and I thought that I could then use a custom classloader and create a new instance of this classloader for each jar file.
    2 problems with this:
    - according to many posts in the different forums I have read, the jar files should not appear in the CLASSPATH (but this would be easier for me if I could use it...)
    - some classes will not be loaded if some classes (present in other jar files) are not loaded... and this makes things really really complicated to implement...
    So, I thought that I was maybe doing this the wrong way, and that there might be an easy way out of this...
    In fact, I do not need to load the classes... all I need to do, is take a sneak peek at the constants and print their values... and that's it!
    Somehow, I think that this is possible to retrieve the values of compile time constants (declared as static final String) as I can see that with Eclipse (when opening a jar file).
    So, my question is: how can I do that within my java application?
    Or maybe there is another easier solution to do what I need?
    Thanks in advance for your help!

    Hi everyone,
    I've been looking for a way to solve this for a week now, without any much success... and I've finally decided to ask the Java gurus for a solution! :-)
    Here's what I am basically trying to do:
    I have several jar files in which there are only compiled code (.class).
    In every class, there are 2 constants (declared as static final String) that I would like to retrieve (one is the version and the other the date of the last modification).
    My goal is to print a list of all the classes in the jar files with the values of these 2 constants for each class.
    The solution that I have right now to do this does not work properly: for now, I read all the elements of the classpath, check if these are jar files, and if so, I look into each one and load all the classes one by one and print the results.
    The problem with this is that it uses the method Class.forName(className) and as some classes are unfortunately present in many jar files (2 or 3 copies), once the classes have been loaded, then it won't be "reloaded".
    Without the possibility to "reload" these classes, I cannot see inconsistencies in the versions of the classes present in the jar files.
    I have read many articles, and I thought that I could then use a custom classloader and create a new instance of this classloader for each jar file.
    2 problems with this:
    - according to many posts in the different forums I have read, the jar files should not appear in the CLASSPATH (but this would be easier for me if I could use it...)
    - some classes will not be loaded if some classes (present in other jar files) are not loaded... and this makes things really really complicated to implement...
    So, I thought that I was maybe doing this the wrong way, and that there might be an easy way out of this...
    In fact, I do not need to load the classes... all I need to do, is take a sneak peek at the constants and print their values... and that's it!
    Somehow, I think that this is possible to retrieve the values of compile time constants (declared as static final String) as I can see that with Eclipse (when opening a jar file).
    So, my question is: how can I do that within my java application?
    Or maybe there is another easier solution to do what I need?
    Thanks in advance for your help!

  • How to extract html file and folder from jar file

    Hi all ,
    I should to submit my project tomorrow . plz help me .
    In my project jar file I have html page that should run when I use the program, I can't extract it . Also it have folder that contain some files that My program should use it . I dont know how to use it from jar file or how to extract it . plz help me.
    If you could I need java could for that.
    Thanks alot.

    Hi all ,
    I should to submit my project tomorrow . plz help me .
    In my project jar file I have html page that should run when I use the program, I can't extract it . Also it have folder that contain some files that My program should use it . I dont know how to use it from jar file or how to extract it . plz help me.
    If you could I need java could for that.
    Thanks alot.

  • How can I add image files to a executable jar file ?

    Could you tell me how can I add image files to executable jar file ?
    package structure:
    ../com/Main.class
    ../images/..

    Please don't cross post, and read this
    http://forum.java.sun.com/thread.jsp?forum=31&thread=271751
    I've answered the question in the New To Java thread.

Maybe you are looking for

  • Adobe Edge Animate CC Language korea Versions ??

    Adobe Edge Animate CC Language korea Versions ?? korea? ( PSY Gangnam Style OK? ^^* ) 한국어 버전은 출시되지 않나요? 한국어 버전도 출시 부탁드립니다. 

  • Fresh JHeadstart installation: empdepdemo gives errors

    Downgraded from JDeveoper 9.03 to 9.02, installed stand-alone OC4J according to the JHS installation instructions and followed the other instructions for setting up the empdepdemo. I had to add some source paths in order to get rid of the ingored, no

  • Re-run a portion of a script

    While *run me* will re-run a script from its beginning, is there any way to re-run a portion of a script from a specific line or command?

  • Anti-Virus for Sun Messeging server

    Dear All I have installed the sun messaging platform with no serious problem and everything looks okay, but really I don't have any idea how to integrate it with Anti-Virus software, the sun document is not complete and also 3rd parties document is n

  • Adding email addresses from numbers to address book

    I am a high school coach and recently I had my players put their names and email addresses directly into my computer using numbers 08. My problem is that every time I try to drag them into my address book, it opens up Mail as if to send out an email.