Access wav-files in jar-archives (URL works, File works not)

Hi there!
The un-jar-ed application works fine, but I have a problem with accessing files in jar archives.
URL url = Classname.class.getResource("testdir/test.wav");works fine (and loading images works this way), but as soon as I try to get the file
File file = new File(url.getFile());I get an null-exception.
(in my case, I use the jmf package to play the sound-files, and I get the problem when I try to instatiate the MediaLocator
MediaLocator mediaLocator = new MediaLocator(url);but I think the problem is the same)
Thanx for help

works fine Then keep doing it that way. What's the problem? It's true that you can't access something in a jar archive via a File object, so don't do that.

Similar Messages

  • Accessing files inside JAR archives

    I have a jar file with structure as follows
    . root directory containing *.class files
    .\dll directory containing *.dll files
    .\images directory containing *.gif and *.jpg files
    Now, when i want to load the dll i use
    System.loadLibrary("dll/sendlib");or to load an image
    ImageIcon i = new ImageIcon("images/"+filename);This works perfectly when the program is not packed in a jar file. I have seen previously that you can use getResourceAsStream(), but in my case it won't work, since it's not class files i'm after. Anyone who have got this to work? Is there some special options in the manifest file that needs to be set, or is the directory structure inside the jar file not the same as outside? How shall i do to load my files?

    if u r using jar file u have to create url object.
    i.e
    URL url = MainclassName.this.getClass ().getResource("/images/"+fileName);
    ImageIcon i = new ImageIcon(url);
    it will work. MainclassName is the name of ur main class
    Paddy

  • How to use database file within jar archive

    Hi. I'm quite new in Java programming, and I'm wondering if what I did makes sense or not.
    In my applet I'm using a MS Access Database file, which is contained in the same Jar Archive like the Applet class file. I tried and tried to use this Database file directly but it wouldn't work. Than I read in some other forum that it is not possible to use the database file directly within the archive. First question: Is that true?
    Than I desided to extract the DB file in the init() method of my applet to the default temporary foulder. When the program is closed I use the destroy() method to delete it again. Everything works well now. But is this the typical way this is done?
    Thanks for help!

    Hi,
    here is the code which extracts the database file out of the jar archive (the same archive in which the class file is):
    //get the user temporary folder
    File TempFolder = new File(System.getProperty("java.io.tmpdir"));
    //create (empty) db file
    efile = new File(TempFolder, "steelSections.mdb");
    // if database file is not yet extracted
    if (!efile.exists()) {
    //get an input stream for the database file
    InputStream in = new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream(
    "FaST/db/steelSections.mdb"));
    //create an output stream for the db file on the file system
    OutputStream out = new BufferedOutputStream(new FileOutputStream(efile));
    //-Buffer to copy the data
    byte[] buffer = new byte[2048]; //buffer to copy the binary
    for (;;) {
    int nBytes = in.read(buffer); //read data
    if (nBytes <= 0)
    break; //no more data to read
    out.write(buffer, 0, nBytes); //write data
    out.flush(); //close out and in streams
    out.close();
    in.close();
    If you have the db file in an other jar archive file you need a referenze to the entry in the other jar archive. I'm not sure how to get this, but I'm sure you fill find a solution by searching in this forum...
    Good luck!

  • Invisible class files inside jar archives

    Hi!
    After developing an application with J2SE 1.4.1_05, under Windows 98, using some packages archived in jar files, I cannot launch the application with the J2RE 1.4.2_02 or J2SE 1.4.2_02 (in the same Windows 98) because the class files in the jars are not 'visible', even if the CLASSPATH is set up correctly. The only classes that work right are the unpacked ones. But it still does work in Windows 2000.
    What might be wrong?

    Thank you for your answer, and excuse me if my question was kind of confusing.
    The issue here is that the files ARE in the jar files (without './' on the front), but in the environment (Windows 98 + J2RE 1.4.2_02) the application does not work, unless I unpack the jars and use the packages in the same manner I did during the development stage (for example, all classes of package 'myutils' in the folder 'myutils').
    The weird thing is that this DOES NOT happen in the environment (Windows 2000 + J2RE 1.4.2_02)!!! Just after installing the J2RE 1.4.2_02 under Win2K, the app does work OK! That is why it seems that ONLY in the first case (Windows 98 + J2RE 1.4.2_02) the class files inside the jars seem to be 'invisible' to the environment.
    As I have mentioned in my question, the app was developed in the environment (Windows 98 + J2RE 1.4.1_05), and it did still work with the jar files, so I wonder if there might be some compatibility between Windows 98 and the J2RE 1.4.2_02.
    Except my own jars, the same thing does happen with the jai_core.jar file coming with JAI 1.1.2. But this does not happen when it comes about rt.jar, in ..\jre\bin!!!
    All in all, the question still is: what might be wrong?

  • Accessing Collaboration Room with Room Link (URL) doesn't work

    hi all
    i'm trying to access a collaboration room by room link (url) but it doesn't work. the room url is: https://www.sportal.ch:443/irj/index.html?NavigationTarget=CollaborationConnector://portal_content/com.sap.ip.collaboration/Rooms/b0ce78ec-3f30-2910-2184-b171271d4d95/workset&NavTargetAsRoot=true
    i have checked the roombackend-properties => they are ok
    i have checked the roles and permissions => they are ok
    what me surprises: when i open a new browser window and type in the mentioned url, our portal-start-page is displayed but in the content area there is no content displaied. i expected, that when i type in the url, then the authentification-dialogue would appear, but it does not.... (does this url only work if i am already logged in the portal??)
    if you have any ideas, how the problem could be solved, please let me know!
    thank you for your help.
    greetings
    flo

    hi ingo
    thank you for the input. i have now solved the problem, perhaps my solution fits for you too. here it is:
    when i use the function "send room-link" the url looks like this:
    https://www.sportal.ch:443/irj/index.html?NavigationTarget=CollaborationConnector://portal_content/com.sap.ip.collaboration/Rooms/9020275c-8348-2810-28a6-a8c1ae60e192/workset&NavTargetAsRoot=true
    with this url i can not access the collaboration room.
    but when i change the url like this:
    https://www.sportal.ch/irj/portal?NavigationTarget=ROLES://portal_content/com.sap.ip.collaboration/Rooms/9020275c-8348-2810-28a6-a8c1ae60e192/workset&NavTargetAsRoot=true
    now i can access the room (with authentification).
    OK, for me the main problem is solved, but can someone perhaps tell me whats the difference between:
    NavigationTarget=CollaborationConnector
    and
    NavigationTarget=ROLES
    thank you for your help!
    greetings
    flo

  • File paths and archiving (and referenced files).

    I've come to the stage where I need to start using referenced files (out of disk space on my laptop) and also start archiving projects. One of my plans was to start keeping an off-site backup of all the originals in case something really bad happened. I'm also going to have on-site backup of projects. But for the off-site originals I would like to have some simple way of finding the photos in case something bad happens, my idea was to simply create a PDF from the list view where I could see the photo and the file path to where it's stored (I plan to store them in simple year-month-day hierarchy).
    The reason why I'm not going to archive the projects off-site is simply the cost, I did a test yesterday and it looks like just storing the originals would be approx 1/3 in size of the projects.
    If someone has a better idea of how to handle this please let me knoe

    I'll try to explain.
    About the cost: Hard disk space is really cheap and I can not see how the cost should be that expensive. This is based on your statement that you still have your images on your laptop and that itself limits the amount of space hence a rather small library.
    When it comes to backing up your projects you have several options. First, if you really want to be cheap about hard disk space (I think you should not since your images really are priceless) you can export projects of your referenced images and not consolidate the images into the exported project. Not to consolidate vs. consolidate images on export really makes a difference in the exported project size. On the other hand, not consolidate images on export of a project makes you back up your images separately, which leads to more work.
    My advice is then; buy two disks (preferable three disks), and export your projects with the images consolidated into one of them and start using the other one with your referenced images.
    I always advice users to have their images in at least three different locations and IMHO the ideal solution for you would be to have your images referenced on one disk and mirrored backups on the other two disks, either one stored in two different locations in case of burglary, fire etc.
    Regards
    Paul K

  • Use classes from a jar archive from in a jar archive

    Hi, I am making a program and I need some the classes in a certain jar archive for tehm to work. Well my program workes before I add it to a jar be when I make it into one and put the needed jar in it, the program breaks. So does anyone know how to access the class of the jar in my jar?

    Well my program workes before I add it to a jar be when I make it into one and put the needed jar in it, the program breaksIt might be easier not to nest the jar files. Instead make the "needed" jar part of the class path when you make your jar file's manifest.
    [http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html]

  • Error with Archiving Faulty Source File in Sender FTP adapter

    Hi All,
    I have configured a Sender FTP adapter with Processing Mode as Archive.
    I am able to read the files from FTP server and archive all the successfuly processed file in the PI aplication server directory XXX/success.
    We need all the error files also to be archived on PI application server in directory XXXXX/Fail so I have checked the option Archive faulty Source Files and provided the application directory  XXXXX/Fail .
    I have unchecked the option Archive Files on FTP server.
    But the problem is when FTP adapter is getting any error files it is not able to archive it to application directory  XXXXX/Fail .
    In RWB it is showing the error
    Unable to archive faulty input file /data/abc.txt to /XXXX/fail/abc.txt
    Cause: com.sap.aii.adapter.file.ftp.FTPEx: 550 rename: No such file or directory
    This directory is existing and works fine when I give this directory name in Archive directory of processing mode.
    Sender FTP adapter is trying to archive the file in FTP server which I dont want and giving us this error.
    If I give any Directory which is present in FTP server my error files are getting archived on FTP server but not in the archived folder.
    I have already unchecked the option Archive Files on FTP server.
    Please help......
    I am on PI 7.11
    Regards
    Henery H

    Hi Henery,
    Check the below thread, this should help you to fix the issue.
    FTP adapter: exc. 550 : No such file or directory
    Thanks,

  • How to deploy ear file with jar file and war file with different names

    Hi,
    As part of weblogic migration from WL 6.1 sp3 to WL 10, Iam facing some problem.
    Problem:
    I have one ear file(abc.ear) to deploy which contains one jar file(xyz.jar) and one war file(pqr.war).
    In config.xml file of WL 6.1, it was mentioned as :
    <Application Deployed="true" Name="abc" Path="./config/mydomain/applications/abc.ear">
    <EJBComponent Name="xyz" Targets="myserver" URI="xyz.jar"/>
    <WebAppComponent Name="pqr" Targets="myserver" URI="pqr.war"/>
    </Application>.
    The above is working fine.
    But in config.xml file WL10,I cannot mention the same.
    I need to have different application anmes for ear,jar and war.If I deploy as a ear file,the jar and war files are deployed with the same ear file name.
    I tried the following options:
    1) Deploying as a ear file by adding <sub-deployments>
    2) Deploying both war and jar seperately which is not recommended in my application.
    Please provide the content I should place in the config.xml so that everything works fine correctly.
    Any help is appreciated.

    Hi,
    As part of weblogic migration from WL 6.1 sp3 to WL 10, Iam facing some problem.
    Problem:
    I have one ear file(abc.ear) to deploy which contains one jar file(xyz.jar) and one war file(pqr.war).
    In config.xml file of WL 6.1, it was mentioned as :
    <Application Deployed="true" Name="abc" Path="./config/mydomain/applications/abc.ear">
    <EJBComponent Name="xyz" Targets="myserver" URI="xyz.jar"/>
    <WebAppComponent Name="pqr" Targets="myserver" URI="pqr.war"/>
    </Application>.
    The above is working fine.
    But in config.xml file WL10,I cannot mention the same.
    I need to have different application anmes for ear,jar and war.If I deploy as a ear file,the jar and war files are deployed with the same ear file name.
    I tried the following options:
    1) Deploying as a ear file by adding <sub-deployments>
    2) Deploying both war and jar seperately which is not recommended in my application.
    Please provide the content I should place in the config.xml so that everything works fine correctly.
    Any help is appreciated.

  • File-XI-RFC, archiving file only when system ack ok. Is it possible?

    Hi !
    We have a File-XI-RFC scenario. We need the file adapter to archive the input file ONLY if the message was delivered ok to the RFC.
    Should this work, using a BPM with this steps ????
    1) Receive (file message type)
    2) Block
    2a) Send (ASYNC to the RFC, with transport Acknowledgement enabled)
    2b) deadline branch at N minutes
    The goal is that if the R/3 RFC receiving system is down, XI does not archives the input file and tries to process it later when R/3 is available. XI's File Adapter should find the file in the source directory because it was not archived when the process returned error the last time it was executed.
    Thanks,
    Matias.

    Hi Bhavesh !
    I'm thinking in other idea, based on yours...
    there should be 2 scenarios:
    Scenario 1: takes file from SOURCE folder,archives it in a VERIFICATION folder, tries to send via RFC.
    Scenario 2: takes file from VERIFICATION folder, checks via BAPI call if its content was succesfully inserted via the RFC of scenario 1, if this BAPI returns OK, send the data to a HISTORIC folder if the BAPI returns ERROR, send the data to the SOURCE folder. I could use the extended receiver determination feature here to select between the HISTORIC and SOURCE folders or BPM.
    Always using EOIO, and file construction mode = APPEND in the receiving file adapters  of scenario 2, to rebuild the input file based on the several splitted messages.
    What do you think ?
    Thanks !

  • How to play wave files from a jar archive?

    Dear friends,
    I have a .jar archive with several .wav files, and I would like to play them without extract these files.
    This is possible to do? If yes, please show me how to do this.
    Thank you for your attention,
    Augusto Nunes

    This discussion of getResource is very useful: http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource

  • How to access a url in file receiver CC with space in the folder name?

    Hi
    PI 7.11 sp4:
    In a file receiver channel I would like to send the message to this folder:
    de-prod.dk\bu\something\something\PTI eventstanden\archive\"
    But I get this error message:
    "Target directory 'F:\usr\sap\XP7\DVEBMGS02\j2ee\cluster\server0\"\de-prod.dk\bu\something\something\PTI eventstanden\archive"' does not exist"
    My question is: where the f.... does it get the 'F:\usr\sap\XP7\DVEBMGS02\j2ee\cluster\server0\  from, and how can I fix it?
    One issue is the space in the folder name. I have tried to replace the space with %20 and then remove the "" s around the whole url, but without any luck.
    When I log on the server on which Pi is running I can access the folder using the mentioned url including the ""s.
    All suggestions would be highly appreciated!
    MIkael

    > But I get this error message:
    >
    > "Target directory 'F:\usr\sap\XP7\DVEBMGS02\j2ee\cluster\server0\"\de-prod.dk\bu\something\something\PTI eventstanden\archive"' does not exist"
    >
    > My question is: where the f.... does it get the 'F:\usr\sap\XP7\DVEBMGS02\j2ee\cluster\server0\  from, and how can I fix it?
    It comes from the "
    Anything else but \ is treated as local folder under working directory of PI
    > One issue is the space in the folder name. I have tried to replace the space with %20 and then remove the "" s around the whole url, but without any luck.
    It works for me just to copy the folder from Windows explorer into channel config. With space and without ".

  • Accessing Video File within .Jar

    Ok, I am creating a project where I am using JMF to display several pre-created videos. The finished project is going to be placed on a cd and submitted in a contest. Because of this, I am compiling the finished project into an executable .jar file. From my previous experiences, I have found that accessing files inside a jar is much more complex than accessing just any old file. The only way I have found to successfully access files inside a jar is through InputStreams (opposed to URLs). This is where my issues begin.
    I have been searching throughout the internet for the past 2 days trying to find any way to create a Player using a type of InputStream. This doesnt seem to be possible the way it is set up. My obsticle here seems to be getting the Manager to realize the File. Here is what I've tried and the errors I got:
    File -- NoPlayerException -- Expected. When creating a file, it doesnt know to look inside the jar for the file, but to the location of the jar instead. Perhaps there is a way to tell URL to look for the file inside the jar. If so, please tell me how.
    File movie = new File("video1.mpeg");
    JOptionPane.showMessageDialog(null, "File: " + movie + "\n URL: " + movie.toURL() + "\n URI: " + movie.toURI() + "\n URL Parsed URI: " + movie.toURI().toURL(), "Error", JOptionPane.ERROR_MESSAGE); //JOptionPane used to display background information while program is running after compiled in .jar
    MediaPanel mediaPanel = new MediaPanel(movie.getURL());
    InputStream -- Compiling Error -- So my primary method of getting Files inside jars are out the window since there is no way to get the URL of InputStreams.
    InputStream movie = getClass().getResourceAsStream("video1.mpeg");
    MediaPanel mediaPanel = new MediaPanel(movie);
    Creating MediaLocator to file location -- java.net.MalformedURLException: no protocol: video1.mpeg -- I assume that basically means I'm screwed.
    MediaLocator movie = new MediaLocator("video1.mpeg");
    JOptionPane.showMessageDialog(null, "File: " + movie + "\n URL: " + movie.getURL(), "Error", JOptionPane.ERROR_MESSAGE);
    MediaPanel mediaPanel = new MediaPanel(movie.getURL());
    Using URL to get into .jar -- NoPlayerException -- No clue about this one. Just tried this a minute ago.
    URL movie = HannibalProject.class.getResource("video1.mpeg");
    JOptionPane.showMessageDialog(null, "URL: " + movie, "Error", JOptionPane.ERROR_MESSAGE); // Displays "URL: jar:file:/G:/Latin/HannibalProject.jar!/video1.mpeg" I do not know if this is correct or not, perhaps someone could tell me.
    MediaPanel mediaPanel = new MediaPanel(movie);If anyone can help me with this, I will be GREATLY appreciative. If anyone needs more information, additional code snippets, ect. please ask and I'll provide what is needed to help me.
    Edited by: Aussiemcgr on Jan 10, 2010 7:03 PM

    And there arises the pain-in-the-ass that is not yet clear to me. For this particular thing, it needs to be an application, not an applet. Which means I have to make it an executable (alternative might be a .bat, havent played with those for anything other than scripts) instead of something embedded. For whatever reasons, this is the efficiency of the school system or whatever the hell it is.
    The simple fact in all of this is that I have no information about the computer this is going to be ran on. Effectively, I am doing this all in the dark right now because I have been given NO guarantee that the computer(s) I attempt to run this on will even have the Java Virtual Environment on it. And, unfortunately, I have no way of finding any of this out because the Computer Program category of these things are not yet been taken seriously so preparation for judging is a last-minute thing.
    Basically, I am wanting to do this with the least amount of possibilities for Murphy's Law (which means I probably shouldnt be using JMF to begin with, but I hate that incomplete feeling) to happen. For the dark abyss I am traveling into, I'm wanting to leave as little external dependencies as possible. For applets, I have to assume that the computer has some sort of browser (sounds stupid, but it is the school system). Not to mention I've designed it from the ground up to work as an application, instead of an applet (roughly 20 hours of work so far, including text research and coding).
    The contest is Jan 30 so the date is approaching real quick. Quite honestly, the more I am looking at it, the more I am starting to consider getting rid of the videos altogether since I am pretty much done with the project with the exception of that. I would have 9 videos total (made only 1 to make sure it would work before making the other 8). The videos itself would only add an additional flair at best, and pretty much guarantee the 1st place for me. My teacher thinks my program's current capabilities, with just a mouse hover and mouse clicking interface with some animated gifs that allows access to several neatly displayed texts, would probably win me first place. However I feel I would go crazy if I actually had legitimate competition for once and lost because I didnt include this damn multimedia. Not to mention I want to include this on my portfolio in the somewhat distant future (along with my Poker Program I finished last month)...I dont know where I'm going with this...

  • Accessing resource files inside Jar using Fat Jar Eclipse plugin

    Hi,
    I want to develop single JAR file that uses a set of other JAR libraries. I am using Fat Jar Eclipse plugin. It works fine. However, I have problem to access resources files (i.e. rdf file) using relative path from my classes. Is there any idea how can I pack, set classpath and use relative path in order to make it works.
    Thanks
    Zoran

    I have solved this problem. The problem was in a way how I have trying to access it. It should be like:
    URL fileURL = this.getClass().getResource("resource/myFile.rdf");
    Zoran

  • Archiving faulty Source file not working in Sender Adapter FCC

    Hi Experts,
    I have enabled "Archiving Faulty Source File" in Sender Adapter FCC and pen down the directory path accordingly.
    Likewise I also enable the processed mode as "archive" and give it the direcotory path.
    However when there is a error flagged in sxmb_moni for this interface, I unable to see any file created in the error folder but I can see a file with timestamp being created in the archive folder.
    I have checked the access right to the directory, so this is not an issue. I ran through the forum on this subject and come across the help.sap note on the following
    " To archive source files where a permanent error occurred during processing, set the indicator.
    A permanent error occurs either during the conversion of the file content, or in a module in the module processor.
    More information: MessageTransformBean, Migrating Dispatcher Classes
    ○       Specify the Directory for Error Archiving.
    ○       To add a time stamp to the archived file, select Add Time Stamp. "
    What is the definition as "permanent error". The error I got in sxmb_moni is a mapping conversion error, so it should be archive this to the error folder, right ?
    Anyone have any such setting enabled and working ?
    Regards
    FNG

    The error I got in sxmb_moni is a mapping conversion error, so it should be archive this to the error folder, right ?
    No, it is not the case. As mentioned on the SAP Help site, for the faulty file to be archived, the error has to occur in content conversion, or in module processor.
    If the error you are getting is in MONI, then it means syntactically the file is correct and hence adapter engine has picked up and sent to integration engine (SXMB_MONI).
    -Supriya.

Maybe you are looking for