Non-image files in JAR

I have solved the problem of loading image files in my JAR by using the getResource() method, but I am having trouble loading non-image files (i.e. text files).
I tried using the same method but I keep getting FileNotFoundExceptions on this line:
File f = new File(getClass().getResource("resources/file1.txt").getPath());
My JAR looks something like this:
com/domain/class1.class
com/domain/class2.class
com/domain/resources/file1.txt

First of all there is no way to access files in JAR file by using java.io.File. second of all, there is no way to access JAR as a jar file by using Class.getResource().
In very general situaltion, evan if you know that your classes and resources are within jar file in your deployment, this does not mean that those resources will be still in jar file in deployed application. Depends from the context resources can be even on other host and url-based access allows you to have them on demand. Using java.io.File is bad habbit in most of the situations and you should hardly try to avoid that.

Similar Messages

  • Keyword and metadata for non-image files.

    Hi, everyone.
    As I have started to use Bridge to browse files in my system including those that are not image files I tried to find information on how Bridge handles the assignment of keywords and metadata to these files but couldn't find anything on Adobe's site.
    Considering non-image files such as PDF's, MS Office (Word, Excel), Text, HTML, and others, how does Bridge handles the assignment of metadata and keywords ? Where are they stored ? Embedded in the files themselves or in a sidecar file similar to what happens to RAW image files ?
    I've read some posts from other users about problems with this. Some report that they are able to assign keywords but these aren't maintained once the file is re-saved.
    Is there a manual on Adobe's site that covers the handling of keywords and metadata in Bridge ?
    TIA,
    Joe

    Joe,
    Being a digital archivist dealing primarily with pages digitized from the turn of the 20th Century for a religious sect I am highly involved in the usage of keywords.  Each page of a work, be it either a volume of a newspaper or a book, contains keywords.  I do not use side-car files but instead incorporate my keywords directly into the resultant TIF file.
    So I used your posting to see what the answer was.  To that end I am presently working on a 1922 title, Thirty-One Years of Organized Work in Oklahoma, Texas, New Mexico and Louisiana by Church of the Brethren from 1891 to 1922, that will consist of slightly over 500 pages.  To test your question I placed the title of the work as a keyword.  I then used Bridge's find ability.  It did not work.
    I forgot that Bridge converts all commas into semi-colons.  And changing the colons into semi-colons still returned no results.  An examination of the keywords tab showed the string broken down in to sections.  Searching for the longest string showed the problem.  Returning to my keyowrd string I removed all instances of the semi-colons and re-searched.  This resulted in a properyl found file.
    So.  The longest string I have tested to date is 120 characters, the title of the work minus the commas.  I suspect that Curt is correct in his assumption that it is limited by the operation system.  I tested this theory by incorporating a double string (without the commas) of my book's title.  This was 241 characters including the space between the duplicated title.  The search was successful.  A triple set of the title returned no hits.
    Wayne Webb

  • Catalog and Keyword Non-Image files

    In addition to my images, I have a growing collection of background and reference information relating to the subject or location of the images.
    I would like Lightroom to be able to Catalog and apply keywords to non-image files.
    I use a metadata search to find my images; I want to be able to use the same tool (Lightroom) and the same metadata (keywords) to find other related information.
    If Lightroom could Catalog and Keyword all Adobe format files (PDF, InDesign, etc.) this would be a great start.
    The next step; selectable list of file-types; export keywords to .xmp

    Joe,
    Being a digital archivist dealing primarily with pages digitized from the turn of the 20th Century for a religious sect I am highly involved in the usage of keywords.  Each page of a work, be it either a volume of a newspaper or a book, contains keywords.  I do not use side-car files but instead incorporate my keywords directly into the resultant TIF file.
    So I used your posting to see what the answer was.  To that end I am presently working on a 1922 title, Thirty-One Years of Organized Work in Oklahoma, Texas, New Mexico and Louisiana by Church of the Brethren from 1891 to 1922, that will consist of slightly over 500 pages.  To test your question I placed the title of the work as a keyword.  I then used Bridge's find ability.  It did not work.
    I forgot that Bridge converts all commas into semi-colons.  And changing the colons into semi-colons still returned no results.  An examination of the keywords tab showed the string broken down in to sections.  Searching for the longest string showed the problem.  Returning to my keyowrd string I removed all instances of the semi-colons and re-searched.  This resulted in a properyl found file.
    So.  The longest string I have tested to date is 120 characters, the title of the work minus the commas.  I suspect that Curt is correct in his assumption that it is limited by the operation system.  I tested this theory by incorporating a double string (without the commas) of my book's title.  This was 241 characters including the space between the duplicated title.  The search was successful.  A triple set of the title returned no hits.
    Wayne Webb

  • Non-image files are not copied to the Backup Location

    I'm on Aperture 3.0.3... I just noticed that non-image files (e.g., WAV files) are not copied into the Backup Location, although they are copied into the main folder location during an import. Does anyone else see this behavior?

    Shawnsat,
    Yes you can still stream from the host computer, the knowledge base article that describes this is http://docs.info.apple.com/article.html?artnum=305098. If you are attempting to display Photos on Apple TV, they must be synced to the Apple TV, per knowledge base article http://docs.info.apple.com/article.html?artnum=305139.
    Cheers,
    John

  • How to pack image files in jar and reference them

    I have a utility project that is used by other applications. I am wrapping the package up in a jar file. The project that is wrapped in the jar file references some jpg file. Can I put those files in the jar? If so, how do I reference them in the code?

    Can I put those files in the jar? Yes.
    If so, how do I reference them in the code?I bet nobody has asked that question before.
    HINT- search.
    EXTRA HINTS - getResource, getResourceAsStream

  • Managing non-image files in iPhoto e.g. wav file

    Hi.
    In the past I had a camera that wouldn't record video, but would record audio and saved them as .wav's. Previously I have managed and organized my photos independently using Explorer (during the dark days of Windows) and now through Finder, and this way I was able to keep these audio files in the same place as the pictures they were associated with. Having now tried to import these folders of images and .wav files I see that iPhoto will not accept files in .wav format, and the thought of having to keep them somewhere completely seperate from the images they're a part of really irks me.
    Does anyone know of a way around this, or have a suggestion for somehow being able to manage the situation? I see video files are no problem for iPhoto to manage, which can even call Quicktime to play the videos if desired... surely there must be a way to deal with .wav's?
    And since we're on the topic - what about other file formats? Most of my pictures (and audio) are from my travels, so ideally I'd like to be able to manage folders that can hold all of my photos, videos, soundfiles and text files (journals) in one place... Don't suppose this is a realistic dream yet is it?
    Thanks everyone

    No.
    Placing any file inside your library folder will appear to not do anything. You won't see a placeholder or anything there. For that to happen, files must be imported. If the file type is not supported, iPhoto will refuse to import. In addition, those extra files inside your library could confuse the database. You might start getting a message upon launch that iPhoto needs to rebuild the thumbnails. But it could get worse. You could cause your database to become corrupted. In that case you would lose all of your metadata: titles, keywords, comments, ratings; lose the relationship between your originals and their edited versions; plus lose your albums, books, calendars, etc.
    So no, it's not safe. Manage them yourself outside of the iPhoto Library folder. You could keep them in your Pictures or Music folder in a subfolder labeled Voice Recordings, or look into the software that TD recommended.
    Regards.

  • Should Spotlight be indexing non-image files inside my iPhoto '11 Library?

    The title says all. I've noticed that certain Spotlight searches sometimes turn up obscure files inside file bundles, such as inside my iPhoto library:
    This doesn't seem normal. How can it be fixed?

    That is generally true: when I want to find something that I know to be inside an application bundle I use EasyFind (and even with that it is necessary to explicitly tell it to look inside bundles). But I just checked using the search for phrase of "PhotoFaces" which is a sub-sub-folder and collection of files inside the iPhoto Library, and Spotlight found it with no problem whatsoever. I presume that whatever magic the programmers did to allow Spotlight's indexer to get photo files just works for everything in the iPhoto Library.
    Francine
    Francine
    Schwieder

  • How does the app know image folder (non class files) wrapped in jar file?

    Hi,
    I created an jar file, client.jar, which wrap all necessary files, including packaged class files ( in a hierarachy structure), image folder, properties folder, and ext folder (containing other jar files used). When I run the jar file, like
    java -classpath c:\tmp\client.jar -jar client.jar
    the app does not know where the images go and could not get the properties files. Actually the image and properties files are contained in the same file: client.jar. How can I fix this. I don't want to extract the jar file back to several separated folders and then run it.
    Appreciate the help.

    Unfortunately you have to make some changes in your code.. to find the pictures you need to replace:
    ImageIcon pic = new ImageIcon("pic.gif");
    with
    URL url = MyClass.class.getResource("pic.gif");
    ImageIcon pic = new ImageIcon(url);
    where MyClass is the class which needs to load the resource.
    I hope this helped you! /Pingu

  • How to delete a jar file after loading image files from it

    Hi,
    How can I delete a jar file after some image files have been loaded? For example, say, I have "a.jar" which contains an image "a.gif" in the root directory of the c drive. I would like to get the image size and then delete the jar file. Here is the code snippet:
        URL url = new URL("jar:file:/C:\\a.jar!/a.gif");
        Icon icon = new ImageIcon(url);
        System.out.println("icon size ? " + icon.getIconHeight());
        File file = new File("c:\\a.jar");
        while(file.exists())
            file.delete();
            try
                Thread.sleep(100);
            catch (InterruptedException ignored)
        System.out.println("file deleted.");I get the image size correctly but just can not delete the jar file. Apparently the file handle is not released, but how to close it? Any hint will be appreciated.
    Justin Jan

    I am sure the URLConnection.defaultUseCaches is set before it is connected otherwise I should catch an IllegalStateException on conn.setUseCaches(false).
            try
                URL url = new URL("jar:file:/C:\\a.jar!/a.gif");           
             URLConnection conn = url.openConnection();
               conn.setDefaultUseCaches(false);
             conn.setUseCaches(false);
                Icon icon = new ImageIcon(url);
                System.out.println("icon size ? " + icon.getIconHeight());
                url.openConnection().getInputStream().close();
                System.gc();
             System.runFinalization();
                File file = new File("c:\\a.jar");
                while (file.exists())
                    file.delete();
                    try
                        Thread.sleep(10);
                    catch (InterruptedException ignored)
                System.out.println("file deleted.");
            catch (Throwable t)
                t.printStackTrace();

  • Error 1003 occurred at Open VI Reference in Dist Copy Non-VI Files.vi- Dist Build LLB Image.vi- Dist Build App Image.vi- Build Application.vi

    When trying to build  an application using labview 7.1 and windows XP,  I get the error
    Error 1003 occurred at Open VI Reference in Dist Copy Non-VI Files.vi->Dist Build LLB Image.vi->Dist Build App Image.vi->Build Application.vi
    I've tried the crtl-shift-run as well as  a mass compile and I still get the error.
    Any ideas?
    Thanks,
    Mike

    Hopefully this thread, or this KB article might help.
    It seems like this could come from a lot of things, but there's suggestions in those which might lead you in the right direction
    Message Edited by Day on 09-22-2006 02:07 PM

  • Editing non-raw image files in Adobe Photoshop

    Hi,
    I am currently digging into the world of Lightroom and setting up a work flow which in my case needs to include editing non-raw files in Adobe Photoshop.
    Please bear in mind that I am quite new to Lightroom so I am not sure I have found all shortcuts and settings to manipulate.
    I will explain what I trying to do (and why) and hope that the community can comment and help put if possible.
    I myself shoot almost everything in RAW format, and I have been using Photoshop (PS) and Camera Raw (ACR) for some years now. I am now on Photoshop CS6.
    But now the amount of images to handle requires a CMS, so I went for Lightroom 4 - hoping/believing that I would find an effective and efficient work flow integration between the two Adobe products.
    But I am more and more also helping others to enhance their images, and I most often get jpg files as image source.
    I am used to using PS layers, filters, smart objects etc extensively to do what I want to do.
    OK, I admin that I already use ACR quite a lot, and sometimes even as the only tool even for jpg images.
    I have began diving/snorkeling with friends and often the images we bring back home is in jpg format, and so far I still believe that the best image "restoration" can be done in Photoshop using adjustment layers, channel mixing and filters to get satisfactory results.
    So now on to my concerns and issues:
    1) Lightroom user interface efficiency - "Edit in"
    When I want to edit a jpg image in Photoshop I :
    action
    comment
    - left click image to select it
    ok, I agree this is needed
    - right click image to bring up context menu
    ok, I agree this is needed
    - move cursor to "Edit in", and wait for another context menu
    ok, ...
    - click "Edit in Adobe Photoshop CS6"
    Yes that's want I want
    - Lightroom presents the "Edit Photo with Adobe Photoshop CS6" selection menu.
    Yes I know, I saw it the last
    nnn times I did it
    - if I need option "Edit a Copy" or "Edit Orginal" I move cursor again, left click to select ,
       move cursor to Edit and left click 
    - and finally Lightroom sends the jpg image to Photoshop as a jpg image
    No, I want a tiff file since that
    is what I have set up in
    preferences
    OK, I know that I can also use the keyboard instead of mouse for this, but the number of actions required from my side is pretty much unchanged.
    For a quick working, Lightroom and PS skilled person, this is just annoying.
    Is this effecient?     Well it depends. For Lightroom beginners this is good. But for me it is a true annoying obstacle
    2) Lightroom "Edit in" - is it effective
    Is this effective?     I say no.      I have specified in preferences that I want PS to receive a TIFF file in Adobe RGB 1998 color space
                                                       Also, I cannot change to TIFF in PS without losing the link between the two images. (If I do, the new TIFF file is not imported by Lightroom, so I have to that manually)
    I have found out that I can choose the path "Select image - select "Open as Smartobject in Adobe Photoshop".
    This will give me a tiff file, and when saved in PS the jpg and tiff files are linked and Lightroom has automatically imported the tiff file into the Catalog.
    What I need / what I would like to know / what I would like to have:
    * Is there a (customizable) keyboard shortcut that enables me to: Select Picture + Use shortcut  - and then I end up in Photoshop (with the Edit option I use 90% of the time) ?
    * Is there a preference that I can set so that jpg images also are opened as tiff files in Photoshop per default?
    * Is there a way to select multiple images and launch them all in Photoshop (and keeping the link between the jpg and tiff files) ?
    * I would like a preference setting allowing me to choose that any new file coming back from Photoshop (after "Edit in" ) is written to a sub-folder, or to a specific folder set by me.
       This would align with my work flow for jpg handling, where the jpg is the "original" and the tiff file is what will eventually end up as image "master" (from where I print,  or produce web / HDTV jpg's).
    * Is there a way to automatically launch a Photoshop Action on the file coming from Lightroom?
       This would also help in my work flow. E.g. I have currently 100 jpg's and avi files which are UW (under water shots) and the adjustment layers I build are always the same (to start with).
       Of course, I can launch the Action once I am in Photohop  - but again, doing 1-5 times is ok, doing it more than 100 times ...
    * I am skilled computer programmer  - can I use Lightroom SDK to write plug-ins to achieve the above enhancements ?
    Regards
    Bosse W 

    * Is there a (customizable) keyboard shortcut that enables me to: Select Picture + Use shortcut  - and then I end up in Photoshop (with the Edit option I use 90% of the time) ?
    -- The keyboard shortcut Command/Ctrl+E will perform steps 2-4 in your above list. You only have to click the Edit button, as the last choice (Edit Original, Edit Copy, Edit Copy with LR adjustments) will be remembered.
    * Is there a preference that I can set so that jpg images also are opened as tiff files in Photoshop per default?
    -- No, a JPEG in Lightroom will always open as a JPEG in Photoshop. If you have made changes to the file that are not supported by the JPEG format (e.g. added a layer) when you go to save the file, it will be saved as either a TIFF or PSD, based on the preference in Lightroom.
    * Is there a way to select multiple images and launch them all in Photoshop (and keeping the link between the jpg and tiff files) ?
    -- Yes, select all the files you want to edit, and use the keyboard shortcut, menu command, or right-click context menu command.
    * I would like a preference setting allowing me to choose that any new file coming back from Photoshop (after "Edit in" ) is written to a sub-folder, or to a specific folder set by me.
       This would align with my work flow for jpg handling, where the jpg is the "original" and the tiff file is what will eventually end up as image "master" (from where I print,  or produce web / HDTV jpg's).
    -- No, there is no automatic way to do this. If you use the Edit a Copy method, the copy is created instantly in the same folder as the original.
    * Is there a way to automatically launch a Photoshop Action on the file coming from Lightroom?
       This would also help in my work flow. E.g. I have currently 100 jpg's and avi files which are UW (under water shots) and the adjustment layers I build are always the same (to start with).
       Of course, I can launch the Action once I am in Photohop  - but again, doing 1-5 times is ok, doing it more than 100 times ...
    -- Yes and No, this is not something that can be setup in Lightroom, but you can set it up in Photoshop using the Script Events Manager.
    * I am skilled computer programmer  - can I use Lightroom SDK to write plug-ins to achieve the above enhancements ?
    -- Yes: http://www.adobe.com/devnet/photoshoplightroom.htmlhttp://www.adobe.com/devnet/photoshoplightroom.html

  • 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.

  • Read images from a jar file?

    Hello, I'm converting a 6i app to 10g. This app does a ton of read_image_file() calls to
    change GIF images on the screen based on user actions. In 6i the images are all stored on the local hard drive. The images are not icons for buttons, but images that appear in different locations on the screen.
    For 10g, is it possible to leave the images in a jar file and effectively read the images from that? Otherwise, I suppose I'm looking at using webutil functionality to download the jar file and unjar it into an images directory for reading from the client?
    Any best-practice scenario for this sort of thing?
    Thanks for any info,
    Gary

    We are migrating from 6i to 10g too. And I try to not use webutil. All my pictures (icons gif files) are in a jar file.
    Just make attention of the size of your pictures. The jar file is loaded when you launch the application (the first time, and after, only if the jar file has changed).

  • Ant help - building a jar with image files.

    I have a jar that contains a handful of image files in a "resources" folder. I used the following command:
    jar -cf resources.jar resources/Now I need to make ANT do the same thing. I tried the following, with no success:
    <property name="build" location="bin"/>
    <property name="dist" location="jars"/>
    <jar jarfile="${dist}/resources.jar" basedir="${build}">
      <arg value="-cf" />
    </jar>In the above example, the "bin" directory contains the "resources" directory that I want to put into the jar. Basically, I need to know how to specify the "-cf" args, and how to specify the target directory as "resources." Can anyone tell me how this is done?
    Thanks.

    Hi micah,
    I can just give you an hint:
    With Ant each tasks has its own properties wich are described in xml. So for your jar generation you should look for the possibilities in the description of the ant task in.
    http://ant.apache.org/manual/index.html
    I guess you need some <include> elements in your <jar> target.
    Regards,
    Martin

  • Issues with Loading Images from a Jar File

    This code snippet basically loops through a jar of gifs and loads them into a hashmap to be used later. The images all load into the HashMap just fine, I tested and made sure their widths and heights were changing as well as the buffer size from gif to gif. The problem comes in when some of the images are loaded to be painted they are incomplete it looks as though part of the image came through but not all of it, while other images look just fine. The old way in which we loaded the graphics didn't involve getting them from a jar file. My question is, is this a common problem with loading images from a jar from an applet? For a while I had tried to approach the problem by getting the URL of the image in a jar and passing that into the toolkit and creating the image that way, I was unsuccessful in getting that to work.
    //app is the Japplet
    MediaTracker tracker = new MediaTracker(app);
    //jf represents the jar file obj, enum for looping through jar entries
    Enumeration e = jf.entries();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    //buffer for reading image stream
    byte buffer [];
    while(e.hasMoreElements())
    fileName = e.nextElement().toString();
    InputStream inputstream = jf.getInputStream(jf.getEntry(fileName));
    buffer = new byte[inputstream.available()];
    inputstream.read(buffer);
    currentIm = toolkit.createImage(buffer);
    tracker.addImage(currentIm, 0);
    tracker.waitForAll();
    images.put(fileName.substring(0, fileName.indexOf(".")), currentIm);
    } //while
    }//try
    catch(Exception e)
    e.printStackTrace();
    }

    compressed files are not the problem. It is just the problem of the read not returning all the bytes. Here is a working implementation:
    InputStream is = jar.getInputStream(entry);
    ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
    try{
    byte[] buf = new byte[1024];
    int read;
    while((read = is.read(buf)) > 0) {
    os.write(buf, 0, read);
    catch(Exception e){
         e.printStackTrace();
         return null;
    image = Toolkit.getDefaultToolkit().createImage(os.toByteArray());
    This works but I think you end up opening the jar a second time and downloading it from the server again. Another way of getting the images is using the class loader:
    InputStream is = MyApplet.class.getResourceAsStream(strImageName);
    In this case, the image file needs to be at the same level than MyApplet.class but you don't get the benefit of enumerating of the images available in the jar.

Maybe you are looking for