Accessing Files within a jar - Problems.

So i have the following code in my program and when i goto run the jar file i get NPE's:
URL fileURL = getClass().getResource("resources/cfg/portlist");
                BufferedReader portFileBuff = new BufferedReader(new InputStreamReader(fileURL.openStream()));Now my jar file has resources/cfg/portlist in it and i cannot figure out why this isnt working for me when it works just fine in another program i have. I feel im missing out on some framing issue. Any Suggestions?

Hello,
I have the same problem when trying to log "log4j" from a jar....
Here is my code that generate the error:
static{
          DOMConfigurator.configure("config"+File.separator+"log4j.xml");
Obviously, the file log4j is in my jar in the directory config.
This code works well outside the jar.
It semms that I got also the same problem on library that are in my jar under the directory "lib"....
Any idea..?

Similar Messages

  • Access a data file within a jar package

    hello, everyone
    I got a problem in locating a data file packaged in jar file.
    For example, in foo.jar there is a data file with the directory path "d1/d2/data.log". In the command line, I want to access that data file by making it as an input to the Main class which will load data.log at runtime. However, it reported exception of "no such file or directory". In the command line, I input:
    java -classpath foo.jar d1.d2.Main d1/d2/data.log
    any suggestion?
    Thanks
    Chinyi

    I don't understand what you're trying to do by including d1/d2/data.log in the commandline? It appears to be extraneous and invalid.
    Assuming:
    that the class you want to execute is Main.class in foo.jar, and that its path in the jar is di/d2, and
    that Main uses d1.d2.data.log when it access this file, it should work.

  • Accessing a Jar file within my jar...

    Hi,
    I've got a JDBC Jar file that I wish to include in my Jar package, but I'm unsure how to do this...
    I'm using ant to compile my code & package it up into the Jar, & I can get it to compile fine, and package everything up fine (including the JDBC jar), but when I go to run the app I get an error
    (No suitable driver).
    My app works fine without being Jar'ed up.
    I'm guessing that I need to set the classpath to reference the JDBC jar file in my jar... but I'm unsure how to do this.
    Any help would be greatly appreciated.

    package what you thirdpart jar file and your jar file to one jar file..
    it will run ok.
    maybe the below tool can help you.
    a tool named JavaJar(written by java) can compress and decompress jar,war, ear and.zip...
    may download from http://www.qwerks.com/download/4114/JavaJar.zip
    the tool is very verygood tool.
    but the homepage(www.pivotonic.com) of JavaJar cannot be accessed.
    it is funny.
    good lucky.

  • Creating a JAR in Eclipse...can't access files in the JAR properly.

    Hi all! I'm a newbie at JAR creation, and am having troubles. I have a project that loads images from image files in my project. I can create the JAR and all, and it runs, but the buttons that have ImageIcons with those IO loaded images are blank. I've tried to include the images when creating the JAR, but it keeps acting like the images never existed. When I run the JAR and have the images separately included in the directory (instead of packing them up too), it won't work as well...UNLESS those images are put in my $HOME directory (Linux).
    Does anyone know how I can properly refer to the images that I'm trying to pack into the JAR from within the JAR? Or, is there a way for the JAR to understand where those images are supposed to be (redirect the focus from the $HOME directory to the JAR's directory)? Any help would be greatly appreciated! :)
    -Keith

    Hi,
    Can the user execute the program through explorer? In Windows Server 2003, the Users group does not have Read and Execute permissions to the command processor (Cmd.exe). 
    You could refer to the article below to resolve the issue:
    "Access is denied" error message when you run a batch job on a Windows Server 2003-based computer
    http://support.microsoft.com/kb/867466
    Best Regards,
    Mandy 
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Accessing files within the Network

    Hi
    I have problem with file sharing. Within the network I have a PC with windows Vista. It has file sharing on. But it is not showing any files in my MAC. Can anyone tell me how to change the settings in my MAC to access files from my PC within the network.

    Hi Avi,
    Thanks for your reply.
    Just to give to some background info. The java class is called from a package that is owned by the same schema. The schema owner is part of the dba_role and connect_role.
    The network drive on the windows 2000 serveris mapped by the domain administrator account.
    We have given permissions to the schema owner to access the mapped drive thru java.
    What the java script does is fill a string array with the name of each file in the directory. The script and error messages are below.
    I have a feeling that the schema account does not have windows 2000 permissions to access network resources, but it is just a hunch.
    Regards,
    Ned
    public static String[] getDirList(String dir, String FilterExt)
    System.out.println(dir + ' ' + FilterExt);
    FilenameFilter filter= new FilterExt(FilterExt);
    File DirList = new File(dir);
    String f[] = DirList.list(filter);
    System.out.println(f.length);
    for (int i = 0; i < f.length; i++)
    System.out.println(f.toString());
    return f;
    java.lang.NullPointerException
    at ImpExpUtil.getDirList(IMPEXPUTIL.java:2254)
    at AutoImpExp.getNewImportFile(AUTOIMPEXP.java:87)
    at AutoImpExp.Import(AUTOIMPEXP.java:253)
    at Tester.autoImportExport(TESTER.java:2135)

  • Run a jar-File and modify a file within this jar-File

    I am running the jar-File, which contains my compiled java files etc.
    The program has a config part, which is saved in xml file.
    This xml file is in the same directory like the class files.
    All theses files are zipped as jar-File.
    Well, I am running the jar file.
    - But how do I open and save the xml file ?
    - Is that possible ?
    - How difficult ist that ?

    I tried to do this some time ago and found out the hard way that you can't, just as DrClap just told you. I would have taken his work for it anyway, but for what it's worth, I thought I'd mention that you're not alone. In my case I wanted to be cute and keep my properties all together within the .jar; thought it'd be cleaner that way. Ended up just creating the more typical class_name-props file in my home directory. Is this what you had in mind?
    ~Bill

  • Problem opening a zip file within a jar file

    Hi,
    I have a jar file in a tomcat web server. The jar file includes a zip file which I've been trying to open with the following sentences:
    SpellDictionary dict = null;
    File f = new File(getClass().getResource*("us_US.zip"*).getFile());
    dict = new OpenOfficeSpellDictionary( new ZipFile( f ) );
    I'm getting this exception:
    2007-09-13 15:31:38 java.util.zip.ZipException: No such file or directory
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:203)
    at java.util.zip.ZipFile.<init>(ZipFile.java:84)
    at com.iir.newsAdministration.textEditor.TextEditorSpellChecker.<init>(TextEditorSpellChecker.java:62)
    If I run the application with the builded classes instead of the jar file, it works fine.
    Any ideas about how can I make it work with the jar file?
    Thanks in advance
    Natalie

    File f = new File(getClass().getResource*("us_US.zip"*).getFile());
    This is not going to work.
    What you need to do is create a Jar/ZipFile from your jar, then extract the ZipFile, put that in a temporary location, then open that with another ZipFile object

  • How do I access files within projects of the same web application?

    Using JDeveloper Studio 11.1.1.1.0
    I'm creating a web application using the Model-View-Controller design pattern. Model represents data, View represents data display, and Controller is control...
    In my application, I created two projects: EJBModel and UserInterface. EJBModel contains the model aspect so it has entity objects and beans to access/manipulate the data. The UserInterface project stores the web interface - mostly jsps. In the UserInterface project, I need a managed bean that calls methods from the beans created in the EJBModel project. I can do this using the @EJB annotation and creating an instance of the class, but since the files are in separate projects that can't see each other and JDeveloper shows an error because it can't find the necessary file. It is best practice to create two projects as it keeps both elements distinct.
    So I wanted to know the best way to access the files stored in separate projects within the same application. Is there a way to package them together?
    Thanks...

    In the UI project, go to project properties->dependencies and add a dependency on the model project.
    This way JDeveloper will know what classes you are referencing.

  • How to access files in a jar file?

    Can anyone tell me how to access a file contained in my jar file?
    I have about 15 classes jarred and deployed as an applet. I want to include in the jar file some .gif files to be used as icons in a tree view. Rather than trying to access them locally with all the security headaches this brings, can I not simply jar them as resources and point to them in my code?
    Any help much appreciated,
    Thanks in advance,
    Chris

    Hello Chris,
    Please read this note taken directly from Sun, from their Java Tutorial/Creating a GUI with Swing/Using Other Swing Features/How to use Icons/Specifying the Image Source (whew!)
    Note:  Applets are supposed to be able to load images from JAR files.
    Currently, however, some browsers can't read images from a JAR file,
    although they do successfully get classes from a JAR file.
    With our applets, we currently hedge our bets by both putting
    the image files in the applet's archive file (the JAR file containing
    the applet's class files) and by putting the image files in the file
    system on the server.
    */So......Do you want to take a chance?
    -Ron

  • How to access files outside a .jar file netbeans project

    Hi, i need to access a file outside a built project inside netbeans. Ideally i would like this file next to the .jar file as myapp.properties. If possible i would like it so that when i am compiling and running the project in netbeans the file can be with the class files or something along those likes. Either way it would be nice to have different code for built projects and just running them outside a jar.
    Heres what i got so far
    properties = new Properties();
                InputStream in = this.getClass().getResourceAsStream("applications.properties");
                properties.load(in);
                in.close();this only works if the file is next to the classes. (think thats called the classpath ? )
    Thanks for any replies!!

    Your wrong code:
    properties = new Properties();
    InputStream in
    = this.getClass().getResourceAsStream("applications.properties");
    properties.load(in);
    in.close();A right code:
    // basic assumption 1: applications.properties
    //  is a pure ISO 8859-1 text file
    // basic assumption 2: the file applications.properties
    //  is stored in the same directory where your
    //  jar file is stored
    properties = new Properties();
    try{
      FileInputStream in      // assume current dir
       = new FileInputStream("applications.properties");
      properties.load(in);
      in.close();
    catch (Exception e){
      e.printStackTrace();
    }

  • Accessing files outside the jar

    Greetings,
    I've got a jar file with some classes, which is in a directory. In this dir there are also some resources. How to access those resources from inside the jar?
    Thanks in advance,
    imaginner

    Try this...
    In your class, add this line...
    String path = System.getProperty("user.dir");
    it will give the path of the folder from which you are running
    your jar file. To this path, add your properties file name
    and start reading it.....
    For example:
    If i have a properties file which both :
    1) should be able to read and edit by users and
    2) should be accessible by classes in jar file....
    I would use the above concept like this.... in my class.....
    String path = System.getProperty("user.dir");
    Properties props = new Properties();
    props.load(new FileInputStream(path+"yourPropertiesFileName"));
    Hope it helps...
    Vijay

  • Accessing files in a JAR from an Applet

    I've been stuck trying to get my applet to work online. The applet and its inner classes, as well as a folder with a bunch of text files it needs to run, are all in a jar file (on a geocities website =/ just trying to get it working). My html code for the applet looks like this:
    <applet code=Graph.class archive="Grapher.jar" height="600" width="1000">
    </applet>
    Graph is the class that runs the applet, and it has some inner classes for buttons and a drawing pane. When I try to run the applet online, I get this error:
    java.lang.NoClassDefFoundError: Graph$MyDrawPanel
         at java.lang.Class.getDeclaredConstructors0(Native Method)
         at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
         at java.lang.Class.getConstructor0(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    I know that Graph$MyDrawPanel is in the jar, and the applet works in NetBeans, what can i do to make firefox look inside the jar to find my inner classes?

    Try this:
    <applet code="InteractiveGrapher.Graph.class" codebase="." archive="monarchive.jar" width="1000" heigth="600">
    </applet>See http://java.sun.com/j2se/1.5.0/docs/guide/jar/jarGuide.html
    See also the example in the java tutorial
    http://java.sun.com/docs/books/tutorial/deployment/applet/browser.html
    (See the code source of the web page)
    hth,
    Message was edited by:
    java_2006

  • SchemaLocation for a XSD file within a JAR

    Hello,
    What kind of shemaLocation should I use in my XML files to reference XSD files located in a JAR so that JDeveloper find it and thus enable code assist feature?
    Note: The JAR in question is in the project library (not necessarily in WEB-INF/lib at the time of development)
    Regards,
    Simon Lessard

    hi Simon Lessard
    If you select "Tools" > "Preferences..." > "XML Schemas", using JDeveloper 10.1.3.2, several "JDeveloper Schemas for XML Editing" have been defined, some inside JAR or ZIP files.
    For example for the ".wsdl" extension like this:
    jar:file:/D:/oracle/jdevstudio10132/jdev/lib/jdev.jar!/oracle/jdevimpl/webservices/wsdl/wsdl.xsd
    Maybe you can define something similar in "User Schemas for XML Editing" in the same dialog.
    Is this what you are looking for?
    success
    Jan Vervecken

  • Unix Executable files within apple programs, problem???????????

    Sometime ago i was using logic pro 7,and saving my project folders on an external drive,,,all of my folders turned into EXE files and couldnt be read,,
    Now ive wiped my internal drive,,reloaded the install disks,,used disk warrior,
    If i highlight any icon such as logic,iDVD,garage band,,or any other,,"show package contents" ???? click contents then open the "MacOS" folder,, A black Unix Executable file is here,,,,in all programs,!!!!!!!!!!
    I have tried to find out if this is normal as i lost a huge amount of project folders,,,,but there is nothing or no one i can find to resolve this issue,
    i would just like to feel safe as im not much of a computer wizard,,
    anyone got an idea? yours confused,, steve

    I have tried to find out if this is normal
    Yes, it is.
    (48530)

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

Maybe you are looking for

  • Oracle 11g - Memory used for sorting

    Hi everyone, I would like to know how I could analyze memory used for sorting in Oracle 11g. When I run the below query, it returns 1531381. select value from v$sysstat where name like 'sorts (memory)';But when I check sort_area_size parameter from v

  • Lock Box Reason Code.

    Hi Experts, I am getting one issue in lock box, If Suppose customer has invoice of $ 1000, he is eligible for discount of $ 50 so he should pay net amount $ 950. But customer is paying full amount without knowing that he is eligible for discount i.e

  • Installed newest Flash Player, "An error occured" message on Youtube videos not working

    I have the latest version of Flash Player (12.0.0.70) and Firefox (27.0.1) installed but I'm getting the "An error occured" message within 1 or 2 seconds of playing a YouTube video. If I uninstall Flash from the computer it works perfectly. Why is th

  • How can I export LDAP portal users

    We are using SSO with LDAP for production portal EP 7.0 users. We would like to export ALL the users. I tried to export all the users under User administration-> Export button but it is not exporting all the users from LDAP Does anyone have any exper

  • Missing songs, missing videos, and missing playlist

    Now that I updated itunes seems like I'm missing videos. Before the update I was and still am missing songs and playlist. This includes songs I had put in with cd's. I don't dare try to sync my phone or ipad. My phone has all the music on there from