Jar file access

Hello
I've packaged my classes and relevent images and html help into a jar file in a structured directory format.
I'm using the method this.getClass().getResource(String path) to access the files.
On linux my program executes 100%, images load, html reads fine no problems
On Windows 98 i cannot access the images in the jar, it throws a null pointer at the resource loader call
Any explanations/solutions?

omw, that makes so much sense i could kick myself :)
eg:
ImageIcon icon = new
ImageIcon(getClass().getResource("images"+File.seperato
Char+"icon.gif"));
must the string be in URL format?Yes, it should be:
ImageIcon(getClass().getResource("images/icon.gif");
I dunno if it is just me, but I sometimes get problems using the getClass().getResource(...) method and usually end up using:
getClass().getClassLoader().getResource("images/icon.gif");

Similar Messages

  • Can a unsigned jar file access the tmpdir (java.io.tmpdir)?

    Hello, according to the JNLP tutor, a signed jar file can access the local file system, but a unsigned one can not. My question is, can a unsigned jar file access the temp directory (the system property java.io.tmpdir)? I think the temp directory should be accessible even though it is part of the local file system.
    Thanks,
    LyLi

    no - unsigned application has no read/write access to the temp dir, but you can use the jnlp api to read and write files with the users permssion.
    see: http://java.sun.com/javase/6/docs/jre/api/javaws/jnlp/index.html for FileOpenService, FileSaveService, and ExtendedService.
    /Andy

  • Different jar files access

    I m facing an unknown problem in my jar file. My manifest file contains-
    Manifest-Version: 1.0
    Class-Path: lib/mysql-connector-java-5.1.5-bin.jar ntools.jar
    Created-By: Tanvir
    Main-Class: Logon
    Yet, in my application a class can't be accessed which is in ntools.jar.If I just put - Class-Path: lib/ntools.jar , then it finds the class.I know that different jar file is separated by space.I did the same thing then why it is not finding classes in one jar but not classes in another jar.

    remove the ntools from the Class-Path entries list.
    it should only contain the external jar

  • Unable to access jar file error !

    hello,
    i have built my netbeans project and obtained the hequalifies.jar file . unfortunately when i'm trying to run this jar file from the prompt command I'mgetting the error: unable to access jar file
    here is the command i'm typing:
    C:\Users\User\Documents\NetBeansProjects\hEqUALIFIES\dist>java -jar " C:\Users\U
    ser\Documents\NetBeansProjects\hEqUALIFIES\dist hequalifies.jar "
    anyone has any clue?
    10x!

    ok i'm gonna make it easier on you.
    i gess i found what is the problem but have no idea how to solve it.
    when i obtained the .jar file i also obtained a README.txt file in which it is written the following phrase:
    ** If a library on the projects classpath also has a Class-Path element*
    specified in the manifest,the content of the Class-Path element has to be on the projects runtime path.
    I'M SORRY BUT I DID NOT UNDERSTAND WHAT IS MEANT BY: what is "the projects runtime path"?
    the content of my manifest is:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: 10.0-b23 (Sun Microsystems Inc.)
    Main-Class: hequalifies.ui.HeQualifies
    Class-Path: lib/PlugIn
    X-COMMENT: Main-Class will be added automatically by build
    I'm having problem with lib/plugin.

  • Access of MySQlL Driver class by eclipse but not from Outside Jar file

    Dear All,
    I have done a standalone application having access with MySQl database.
    I could access it when i execute it from eclipse. But when i export it into Jar file and running I get MySQL Driver class not found exception.
    Give me a better solution for this issue.

    CLASSPATH, CLASSPATH, CLASSPATH.
    You have defined the Eclipses Project Library Path to include the MySQL jar, but ar not including it on the classpath when executing the jar.
    Either modify the MANIFEST.mf file in the jar to include a reference to the MySQL driver jarfile or call java in the following manner
    java -cp /full/path/to/MySQL/Driver/jarfile.jar -jar yourJarFile.jarObviously, if this is on Windows and you are executing through a double click, the first option is the best option.

  • How to access additional supporting jar files from EJB JAR?

    Hi,
    How can we access additional supporting jar files as part of my EJB JAR .
    I don't want to keep them in the top level because other EJB JAR files also has
    the same jar files(code in the classes in the jar is slightly different)
    can I keep the additional jar files in my EJB JAR?
    Thanks
    NLB

    Include the supporting jar files in the Ejb jar file.
    Specifiy the jar files in the Ejb jar manifest file.
    Manifest-Version: 1.0 [CRLF]
    Class-Path: utility.jar [CRLF]
    thanks,
    Deepak
    "NLB" <[email protected]> wrote:
    >
    Hi,
    How can we access additional supporting jar files as part of my EJB JAR
    I don't want to keep them in the top level because other EJB JAR files
    also has
    the same jar files(code in the classes in the jar is slightly different)
    can I keep the additional jar files in my EJB JAR?
    Thanks
    NLB

  • How can  I access my java class file in a .jar file ...PLz Help anyone!!

    Hi Folks,
    I am new in Java programming, have a .jar file that contains .java files that I want no access and use from another .java file. These files in the .jar file basically form a library thus have no main-method. However I can not declare an instance of the library (in the .jar file) and use it within my program.
    Plz help ...I have tried all I know in vain.
    Thanks.

    temba wrote:
    Hi Folks,
    I am new in Java programming, have a .jar file that contains .java files that I want no access and use from another .java file. These files in the .jar file basically form a library thus have no main-method. However I can not declare an instance of the library (in the .jar file) and use it within my program. You are making little sense. You can't instantiate .java files.
    Plz help ...I have tried all I know in vain.
    Thanks.Could you post WHAT you have tried and also post what error messages you received?

  • Error message at start-up Unable to access Jar file

    I am a consumer, not a business...and not an IT professional. I am running Vista and have not installed any new software recently.
    At every start-up, I get a pop-up titled Java Virtual Machine Launcher. The message says "Unable to access jar file". C:\users\user\.jnana.jnana.tsa.
    Any idea how to fix this?
    Thanks in advance.
    Edited by: 794979 on Sep 15, 2010 5:31 AM

    ok i'm gonna make it easier on you.
    i gess i found what is the problem but have no idea how to solve it.
    when i obtained the .jar file i also obtained a README.txt file in which it is written the following phrase:
    ** If a library on the projects classpath also has a Class-Path element*
    specified in the manifest,the content of the Class-Path element has to be on the projects runtime path.
    I'M SORRY BUT I DID NOT UNDERSTAND WHAT IS MEANT BY: what is "the projects runtime path"?
    the content of my manifest is:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: 10.0-b23 (Sun Microsystems Inc.)
    Main-Class: hequalifies.ui.HeQualifies
    Class-Path: lib/PlugIn
    X-COMMENT: Main-Class will be added automatically by build
    I'm having problem with lib/plugin.

  • How to access a jar file in EAR file?

    I have a EAR file which contains EJB.jar file and util.jar file. Outside of EAR, I mean in client side, I need to reference util.jar file. How can I access it?
    EAR structure is
    |--+META-INF/
    |--|---application.xml
    |--|---manifest.mf
    |--EJB.jar
    |--|---+MEAT-INF/
    |--|---|--- deployment descriptors...
    |--|---|--- manifest.mf
    |--|--- EJB classes
    |--Util.jar
    Util.jar must be executed in server side. If I just add Util.jar in client program's classpath, when client program is executed, serverside Util.jar is executed? Or what else I should do in the client program to reference server-side Util.jar?

    Excellent question. I don't see any client-jar in your EAR file structure. So I am assuming you are writing a separate client application which will talk to the ejbs deployed as part of this EAR. You need to do the following:
    Write another EAR file with the following structure:
    ear:
    META-INF/application.xml
    util.jar
    client.jar
    client.jar should have a META-INF/MANIFEST.MF and that should contain Class-Path:util.jar and value for Main-Class attribute.
    Now deploy this new ear to your application server and execute it using Application Client Container that comes with your app server.
    If you don't want to write another EAR file, then bundle th client.jar in your original EAR file.
    Points to note are:
    you have to repackage util.jar again inside this ear file.
    For portability reason, you should use Class-Path manifest entry in client.jar. Refer to http://java.sun.com/j2ee/verified/packaging.html and J2EE platform spec section #8.2.
    Hope this helps,
    Sahoo

  • 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 classes in jar files

    hi I have added a jar file to my project in eclipse.How to access the classes in that jar file?

    cu is right.
    classloader returns the URL of your resource. You can the jar using something like the following...
    ClassLoader classloader = this.getClassLoader();
    url = classloader.getResource("your_resouces...");
    if(url == null)
    System.out.println("cannot find resource ");
    return null;
    String jar = url.getFile();
    jar = jar.substring(jar.indexOf("/")+1, jar.lastIndexOf("!")).replace('/', '\\');
    obviously, this code snippet works on windows only. Now you have the jar file path. I use Jar file classes to access the jar file. (e.g. you can search for each class files)
    Ming

  • Access jar file from in-memory classes...

    I have some classes that I compile to memory and everything works fine until one class that must access some external jar files. I have been unable to access those jar files from disk after trying every suggestion using URLClassLoader. I even tried someone's example to hack the SystemClassLoader which properly adds the jar file paths, but still they can't be seen. The only way it works is if I put the files in the jdk/jre/lib/ext directory. Then everything works fine. There must be a way to load the jar files in memory as well as the class files so they can be accessible. Has anyone done anything like this? Is it possible? Even though the class files are in memory, why would the jar files not be seen even when they are added to the same URLClassLoader's URL's. Thanks.

    Sorry that wasn't clear. What I mean is that the classes are compiled to byte code directly to memory and no physical .class file is created. Yes, I'm using my own ClassLoader that extends URLClassLoader and I'm setting the parent to ClassLoader.getSystemClassLoader(). I also should mention that I'm doing this inside a Netbeans module that is part of a Netbeans Platform application. I don't know why that should matter though, since I'm trying to do everything in memory without creating the physical files. Thanks.

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

  • How to access images in a jar file

    Hello,
    I am currently developping a swing application that uses icons (gif files) and I have zipped all my classes and images in a single .jar file.
    When I try to access those files it doesn't work ... it seems that I am not using the right way ...
    Could anyone explain me how to achieve this ?
    thanks in advance

    I get the Images from jar file to set ImageIcon for my components like this:
    ImagesLocator.getImage("imageName.gif");
    anu
    //ImagesLocator.java
    import java.net.URL;
    import java.awt.*;
    import javax.swing.*;
    * Load images from correct place (directory or JAR file) into GUI.
    public class ImagesLocator
         * Load image from correct place (directory or JAR file).
         * @param imageName name of image to be loaded (with no path)
         * @return loaded image
         public static ImageIcon getImage(String imageName)
              ClassLoader cl = ImagesLocator.class.getClassLoader();
              ImageIcon i = new ImageIcon(cl.getResource(imageName));
              return i;

  • Protecting the jar files from being web access

    I have a jnlp file which is put under tomcat webapps folder, say (\webapps\TEST\launch.jnlp), with the jar and lib files put in the subfolder (\webapps\TEST\folder1\*.jar AND \webapps\TEST\folder1\lib\*.jar).
    My question is how can i prevent user from direct access to the jar files via typing http://www.someip.com/TEST/folder1/main.jar ? I tried the following methods but it seemed not working:
    1. Change the folder permisson in \webapps\TEST\*.*, but when user type the above hyperlink they can still get the jar file
    2. put the jar and related files under \WEB-INF\, but now this time running the launch.jnlp, it returns an error saying that it can't access/find the WEB-INF.
    Is there any method? Or should I say, when you published jnlp to web, the related jar files are forced to be accessed by everyone.

    Sounds easy to me: encrypt your xml, then instead of just storing your key as plain bytes do some reversable operations on it (xor masks, reversions, whatever you like), just do them in many different points (and classes) of your code, have some parts done by methods that actually check application is running under JWS with proper codebase, scramble it all, and suddently the whole stealing operation won't be worth the effort. Obviously you should have many private (and package protected) methods, seal packages and so on. Maybe, somehow, you can even use reflection to identify calling classes (not sure, never looked for anything similar).
    What else? write down some c++ code into your own dll/JNI library and make it do something too, so they'll even need to decompile the dll. If you know first execution is always online you can send another xor key and store it with persistence service or write it down to windows registry. You can keep making it harder as much as you like, even just with silly code like
    Math.ceil((new GregorianCalendar.getField(Calendar.YEAR)%2000)/1000)*((int)('c'-'a'))just to retrieve the number 2. If you distribute such code through many lines and methods, once you scramble it, most people will give up.
    Bye.

Maybe you are looking for

  • Time Capsule or External HD?

    Hi. Currently using a Lacie 1TB external drive for my TimeMachine backup, abuot to buy an addition 2TB drive to "piggy back" my existing one. Just looking for advice regarding would i be better buying a 2TB Time Capsule instead of a Additional extern

  • Http error: could not post the file?

    Hi, We have a WebDynpro Application to XI scenario where the WebDynpro app calls the XI generated WebService, passes data to the webservice, and synchronously receives data in the webservice itself. As i unserstand, in this scenario, a receiver SOAP

  • Please HELPPP! Apple ID messed up

    Please Help me...My husband decieded that he wanted to switch his Galaxy for my old Iphone 4s. So we did the switch online...I totally reset the phone to factory settings so he could get it all set up. Once he got his Icould and apple id all set up A

  • Can I upload music from iPod to iTunes? My music has disappeared from my iTunes account, but still have it on iPod.

    Music on my iTunes account has disappeared, but still have it on my older iPod; want to upload it to iTunes, but when I hook up to computer, iTunes wants to overwrite the iPod.  I fear I'll lose it all.  Any help?

  • Get component closest to point x, y

    Here is a fun one... I have a JPanel with various Components in it that are layed out manually (ie.. null layout). When the user clicks in this JPanel I would like to know which of these Components is closest to the point where the user clicked. Does