Load a file located in JAR

Hi all.
I've got a folder which contains files, a class which owns the Files (configuration.java). This class is a utility class and is packaged as a jar (conf.jar) which is located in WEB-INF/lib. My files are located in a folder in the same jar than configuration.java
A servlet, at server startup verify each attribute File in my class (configurationLoader.java).
How can I load my files ?
This is what looks like my EAR :
WEB-INF
| lib
| | con.jar (contains configuration.java)
| | | configuration.java (pkg fr.myclasses)
| | | file1 (pkg (fr.directory)
| | | file 2 (pkg fr.directory)
| | | ...
I tried to use (File file = new File("directory/file");). As I thought it's useless.
If someone can help me ...
Thanks in advance.
florent_b
Message was edited by:
florent_b

Sounds good to me.
The other option would have been to leave them in the jar and use the Class.getResourceAsStream method, which searches the classpath for the requested resource.

Similar Messages

  • Finding loaded Class file from particular Jar

    Hi,
    I have multiple jars containing same class file.
    How can I find out that the loaded Class file belongs to particular jar?
    Thanks
    madan

    In most cases it's possible with ProtectionDomain and CodeSource:ProtectionDomain pd = YourClass.class.getProtectionDomain();
    CodeSource cs = pd.getCodeSource();
    if (cs != null) {
        System.out.println("It came from " + cd.getLocation());
    } else {
        System.out.println("Location unknown.");
    }For further information see
    [url http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#getProtectionDomain()]http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#getProtectionDomain()
    http://java.sun.com/j2se/1.4.2/docs/api/java/security/ProtectionDomain.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/security/CodeSource.html

  • Loading flat files located on a server using the Control Center piece ofOWB

    Loading flat files from a server with OWB
    I am successful loading files with OWB, as long as they resided on my workstation in the C:\ drive. I copied the files to a Linux server into directories owned by Oracle/oinstall, permissions on the directories containing the files are 777. I ran the OWB client from the server with the following results:
    Error
    RPE-01013: SQL Loader reported error condition, number 1.
    SQL*Loader: Release 10.2.0.1.0 - Production on Fri Mar 9 11:15:58 2007
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    SQL*Loader-500: Unable to open file (/u00/data/owb_repos1/state_codes.csv)
    SQL*Loader-553: file not found
    SQL*Loader-509: System error: The system cannot find the file specified.
    SQL*Loader: Release 10.2.0.1.0 - Production on Fri Mar 9 11:15:58 2007
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    SQL*Loader-500: Unable to open file (/u00/data/owb_repos1/state_codes.csv)
    SQL*Loader-553: file not found
    SQL*Loader-509: System error: The system cannot find the file specified.
    I tried to load the file using the control center from both the windows client and the server client. Can I do this from either one?
    I can't import the file in the Design Center from the /u00/data/owb_repos1 directory, it does not show up.
    If anyone has received similiar errors from OWB, please tell me how I can fix this. THANKS!!!
    [d97886@owbtest owb_repos1]$ pwd
    /u00/data/owb_repos1
    [d97886@owbtest owb_repos1]$ ls -la
    total 24
    drwxrwxrwx 2 oracle oinstall 4096 Mar 19 12:14 .
    drwxrwxrwx 18 oracle oinstall 4096 Mar 6 16:41 ..
    -rwxrwxrwx 1 oracle garrett 1481 Mar 8 07:32 state_codes.csv
    [d97886@owbtest owb_repos1]$

    Hi
    This is what i do for my flat files (i am loading my tables from the flat files):
    1) Create location for the files in OWB and it should look something like \\path_to_where_the_files_are. Here you should be able to browse to your Linux box and select the location of the files.
    2) Then check whatever you use (i use TOAD) and you should see in owb schema a directory created there which points to the location of the flat file.
    3) then just follow the guide to sample the files etc and you are good to go.
    Basically OWB has to be able to see the files that are on Linux machine.
    Alternatively you can map your Linux share to your windows box (use samba or something) and use it that way.
    Sorry if it is stating the obvious.
    Hope this helps
    Kind Regards
    Vix

  • How to load xsl-files out of jar-files

    Hi,
    I have included some xsl-files into a jar-file. I can access this files with the following code-snipped if the jar-file is local on my harddisk:
    ClassLoader.getSystemClassLoader().getResource("pcodeliste.xsl").openStream()
    But the problem is that I use this jar-file as a part of a j2ee-application (it's a ear-file). After deploying this ear-file to my application-server (oc4j) I get a null-pointer exception if I call the xsl-file with the code above.
    Can anybody help me how to change this code or how to change the j2ee-application to have access to this files??
    Thank you very much
    Tobias

    Hi Rykk!
    Thanks for the answer, but it does not work since the jar, containing my file is inside an ear.
    Greets,
    Jay

  • Can't load sql file from inside jar file?

    hi all
    i have a sql file inside my jar file
    and i want to get the path of the sql file to use it in runtime command to restore a sql dump file
    i used the following but it doesn't work:
    the path contains invalid characters such %20% instead of and?
    URL url2=getClass().getResource("backup.sql");
    String str1=url2.toString().substring(10);
    String command="cmd.exe /c  c:\\wamp\\mysql\\bin\\mysql -u root --password=anasa library < "+str1;       
    Runtime.getRuntime().exec(command);is this way is wrong?
    or there's an alternative way?

    How is the system to pull the data out of the jarfile?
    That redirection symbol means to take the information from the file, or here document, or command output that comes after it, but you don't have any of those. It will read that String as if it is a file name, but a file under that name doesn't exist. And, after you've changed it like you have, it doesn't even reference anything inside of a jar file anymore (not that the command could have used that anyway).
    If you insist on doing something like this, then you are going to need to read it with getInputStream and write it out somewhere (probably to a temp file) then use that tempfile and delete it when you're done.

  • Include a JSP file located in a JAR

    how is it possible to include a jsp file which is located in a jar? perhaps someone has already a solution for this hoping
    what I already have found out is that jasper parser supports loading JSP files out of JARs, indeed. but when using a <%@import file="foo.jsp"%> directive, this special method is not called. is there some workaround? should I set some special property?
    thx

    Did you ever figure this one out?

  • Java 7: Problems launching applets with jars on "file://" location

    Hi,
    We are experiencing a problem when updating our client's JRE from Java6 U 21 up to Java7 U 55.
    We have developed an Applet which is composed by several JAR files. Some of those JARs must be stored in local drive, and the JAR with the main Java class is stored on server.
    Let's supose we have a similar scenario like this:
    https://blahblahbah/bar.jar
    https://blahblahbah/test.html
    C:/foo.jar
    The code of test.html:
    <embed
      archive="file:///C:/foo.jar"
      cache_archive="bar.jar"
    />
    This code works fine on Java 6 and Applet is correctly loaded.
    However, with Java 7 a security exception is raised when trying to load JAR files from "file:///" location during Applet launch:
    java.lang.SecurityException: Permission denied: file:/C:/foo.jar
        at sun.plugin2.applet.Applet2Manager._loadJarFiles(Unknown Source)
    We have tried several tests using a java.policy file which grants all possible permisions:
    grant codeBase "file:/C:/foo.jar" {
        permission java.security.AllPermission;
    grant {
      permission java.security.AllPermission;
    We also tried to low Java's security level to "MEDIUM", with no success.
    We finally only managed to run the Applet if we explicity disable the "Next-Generation Plugin" with Internet Explorer 8. However, that's not a suitable solution, and still does not work with Mozilla family browsers.
    Eventhought with Mozilla browsers is still not working.
    Is there any restrictions in Java 7 that prevents to read jars from being loaded from local drive when launching Applets?
    Thanks in advance,

    Thank you baftos.
    I had read the whole message before posting mine. It's not the same problem. I'm able to run the sample signed applet always having the jar in the same location than the HTML page serving the applet via JNLP:
    <jar href="SignedAppletTest.jar" main="true"/>
    However, the security exception raises when trying to read that jar from local drive:
    <jar href="file://C:/SignedAppletTest.jar" main="true"/>
    ExitException[ 3]java.lang.SecurityException: Permission denied: file://C:/SignedAppletTest.jar
        at sun.plugin2.applet.JNLP2Manager.loadJarFiles(Unknown Source)
    I have even tried to decompile JNLP2Manager class, without seeing anything useful on that loadJarFiles method
    The only way I managed to avoid the problem is unchecking the New Generation Plugin and running the Applet with IE. Not a suitable solution for me at all..

  • ClassLoader in JAR file not loading config file properly

    Hi all,
    I have an application that I am going to deploy using JavaWS, and everything works fine except for one little hitch. I have a configuration file, nvacconfig, located at NVAC.jar/config/nvacconfig. I'm trying to load this file into my application using a ClassLoader, but it does not seem to be working.
    I have a method from a certain class that loads the configuration file. The class is not important, as it is part of an API that I cannot alter. This class has a load(String file) method, that loads the specified configuration file with a String argument. This works fine when I run my application from the command line and when the configuration file is not located in the JAR, but I need to include this configuration file in my JAR, so I can run my app in the JWS sandbox.
    To load the file when it is NOT inside a JAR, and is simply located at config/nvacconfig, I just use:
    id.properties.load("config/nvacconfig");and it loads the configuration file, nvacconfig.
    When I include the file in my JAR and try to load it using a ClassLoader, it does not seem to work, and the load method cannot find the file. This is how I am trying to accomplish this:
    ClassLoader cl = this.getClass().getClassLoader();
    URL url = cl.getResource("config/nvacconfig");
    String file = url.toString(); //I have also tried String file = url.getFile();
    id.properties.load(file);This does not work, and I'm not sure why.
    Is there something I am doing wrong? Is this the wrong way to go about this?
    Any advice would be greatly appreciated.
    Thanks,
    Dan
    Message was edited by:
    Djaunl

    try this:
    import java.io.*;
    import java.util.jar.*;
    import java.util.zip.*;
    public class ExtractFromJAR {
         public void extractFileFromJAR(String dest, String fileName) {
              try {
                   String home = getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceAll("%20",
                   JarFile jar = new JarFile(home);
                   ZipEntry entry = jar.getEntry(fileName);
                   File efile = new File(dest, entry.getName());
                   InputStream in = new BufferedInputStream(jar.getInputStream(entry));
                   OutputStream out = new BufferedOutputStream(new FileOutputStream(efile));
                   byte[] buffer = new byte[2048];
                   for (;;) {
                        int nBytes = in.read(buffer);
                        if (nBytes <= 0)
                             break;
                        out.write(buffer, 0, nBytes);
                   out.flush();
                   out.close();
                   in.close();
              } catch (Exception e) {
                   e.printStackTrace();
         public static void main(String args[]) {
              new ExtractFromJAR().extractFileFromJAR(".", "file.txt");
    }

  • Problem loading image from jar file referenced by jar file

    First, I searched this one and no, I didn't find an answer. Loading images from jar files has been pretty much done to death but my problem is different. Please read on.
    I have my application, a straight up executable running from Eclipse. It uses a jar file, call it JarA. JarA launches a GUI that is located in another jar file. Call it JarB. To recap:
    My application calls JarA -> JarA loads classes from JarB -> JarB looks for images to place in a GUI it wants to show on the screen
    When JarB goes to load an image the following happens:
    java.lang.NullPointerException
         at sun.misc.URLClassPath$3.run(URLClassPath.java:316)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.misc.URLClassPath.getLoader(URLClassPath.java:313)
         at sun.misc.URLClassPath.getLoader(URLClassPath.java:290)
         at sun.misc.URLClassPath.findResource(URLClassPath.java:141)
         at java.net.URLClassLoader$2.run(URLClassLoader.java:362)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findResource(URLClassLoader.java:359)
         at java.lang.ClassLoader.getResource(ClassLoader.java:977)
         at org.cubrc.gmshell.gui.MainWin.preInit(MainWin.java:152)
         at org.cubrc.gmshell.gui.MainWin.<init>(MainWin.java:135)
    The code from JarB that loads the image looks like this:
              URL[] oSearch = {Main.class.getResource("images/")};
              URLClassLoader oLoader = new URLClassLoader(oSearch);
              imgIcon = new ImageIcon(oLoader.getResource("icon.gif"));
              imgMatchRunning = new ImageIcon(oLoader.getResource("gears.gif"));
              imgMatchStill = new ImageIcon(oLoader.getResource("gears-still.gif"));
              imgMagnify = new ImageIcon(oLoader.getResource("magnify.gif"));This looks right to me and JarB certainly has an images directory with those files. But I'm in hell right now because I don't know where to place the images to make this work or if you can even attempt to load images with a dependency chain like this.
    Any help very appreciated!

    Have you tried to move your image-files out of the jar file and place them in the sam folder as the jar-file? I think that would help.
    When you try to load the image-file you get the NullPointerException because the program tries to read a file it can't find. Remember that a jar file IS a file and not a directory.
    If you want to read somthing inside the jar-file you need to encode it first.
    Have you tried to read the jar-file with winRar. It makes it easy to add and remove files in your jar-file.

  • 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();

  • Load multiple files using the same data load location

    has anybody tried loading multiple files using the same load locations. I need to do this as the data in these multiple files will need to be exported from FDM as a single export file. the problem i am facing is more user related. since these files will be received at different points of time, users will need a way to tell them what has been loaded and what is yet to be loaded.
    is it possible to throw a window on the web broser with OK and Cancel buttons from an event script?
    any pointers to possible solutions will be helpful

    was able to resolve this. the implementation method is as follows
    take a back up of previously imported data in the befcleardata event script. then in the beffileimport event append the data to the import file. there are many other intricacies but this is the broad implementation logic. it allowed my users to load multiple files without worrying about append or replace import type choices

  • How to load a file with out specifying its absolute location

    Hi,
    I'm having some config files in a specific location. I'm setting that folder path to the CLASSPATH and trying access those file just by giving its name.
    For eg: contents are in e:\config folder
    I set e:\config to CLASSPATH
    and trying to load the file which is in the above said folder.
    using getResourceAsStream(filename).
    The above approach is working in certain cases, but not working when i try to do in a class which under a big package structure.
    Can someone help me out, the reason for this unexpected behaviour.
    Please do suggest me, if u know some work-around for this problem.
    Thnaks in advance,
    Chandrasekhar

    Hi,
    Thank you. I tried by adding a forward slash, it started working.
    But I still have one doubt, when the program is within the package structure, then we have to give forward slash, where as if the program doesn't have any pkg structure we have to give only the file name without prefixing the slash.
    Any idea, why is it so ??
    Is it bcz, that getOutputAsStream() will prepend the package names, if forward slash is not given. Even if this is true, why providing a forward slash in a program with no packages doesn't work ?

  • In PI 7.1 - Java UDF's Compiled Class files - Jar File location

    Hi All,
    In PI 7.1 Does anybody know where the compiled Java UDF's (which are used in Graphical mapping) class files stored in jar are located in integration server? I want to use this jar file in my XSLT mapping.

    Hi,
    I guess it would be under
    \usr\sap\<SID>\DVEBMGS00\j2ee\cluster\server0\temp\classpath_resolver
    or
    \usr\sap\<SID>\DVEBMGS00\j2ee\cluster\server0\.\temp\classpath_resolver
    Where SID is your XI instance name.
    Thanks,
    Gujjeti
    Edited by: Praveen Gujjeti on Jun 23, 2008 5:12 PM

  • Changing swap file location on tray-loader iMacs

    This is not a question, but something I discovered that makes my old tray-loader iMac (the oldest iMac models) run Mac OS X much better.
    As you may know, these oldest iMacs have an 8GB size limit on the boot volume. The largest stock drive on these iMacs was 6GB. That means if your upgraded hard drive is larger than 8GB, it must be partition so that the first partition is under 8GB (7.78GB on my iMac), and it must be the boot partition where the OS is installed (whether it's Mac OS X or 9).
    In my case, I have a roomy 120GB hard drive (I believe the useable limit on these iMacs is 128GB). The first partition is just under 8GB, the second partition is the rest of the space, about 104GB. I have used every trick out there to move files (such as the iTunes music folder and most of my user/documents files) off to the second partition, to make free space on the boot partition as large as possible. So I have 3.5GB free on my 8GB boot partition. This is about 40% of the volume's total space so it seems pretty good, until you realize that most recent Macs have much more than the TOTAL 8GB I have, as free space on the boot volume. Mac OS X was just not designed to work well with small boot volumes...
    Mac OS X uses the free space on the boot volume for its virtual memory "swap file." Considering these old iMacs max out at 512MB of RAM, virtual memory is being used quite a bit. But since space on the boot volume is very limited, low RAM and lack of free space can lead to performance issues. Here's what I observed. When I initially started up my iMac, I had about 3.5GB of free space. Over time, as I used more and more apps, that free space would diminish until I had only about 600MB remaining (as reported by a Finder window). At the same time, I noticed performance getting bogged down and more "chugging" sounds coming from the hard-working hard drive.
    I've known about changing location of the swap file, but never tried it until recently. During the Mac OS X boot process, the Mac sets the location of the swap file. By default, the swap file resides on the boot volume (I believe most other Unix-based systems use a dedicated "swap partition" for the swap file). Since most recent Macs have large drives set up as one partition (and there is plenty of free space), and since many users have upgraded their RAM (and virtual memory is not as critical), swap file location is usually not an issue, and there is certainly no need to change the swap file location. However, on my iMac with an 8GB limit on the boot volume and 512MB of RAM, it made a noticeable difference.
    I found one set of procedures on the web that was much better than the others I found for changing the location of the swap file.
    http://www.math.columbia.edu/~bayer/OSX/swapfile/
    On this page, there are two choices for Panther users. I used the one that works for both Panther and Tiger, because it appeared to me to be more straightforward. The author intentionally keeps the instructions somewhat technical to discourage users who are not technically inclined. I don't consider myself to be too "geeky," but I can follow instructions and type a few commands in Terminal.
    After I changed the swap file location to a large mostly empty volume, I noticed much better performance when I have many large apps open at the same time. Performance no longer degrades over time, and the free space on my boot volume remains a constant 3.6GB.
    The reason for this post is to share this information. Some users of these old iMacs may be noticing the same issues I had. This is a possible solution. However, if everything is OK with your set up, there is no reason to change the swap file location. If you try it, be sure to take the usual data backup precautions.
    If anyone else has experience with changing swap file location, please post your comments here.

    Problem has been solved:
    background.setCapability(Background.ALLOW_IMAGE_WRITE);Thanks everybody for reading this :)

  • Hyperion Shared Services jar file css-9_3_1.jar in different locations

    Dear All,
    We found that HSS jar file, css-9_3_1.jar, can be found in many different locations as shown below. Doing a Unix diff, they are not all the same. I just wondering why was that. Currently, there seems no problem. But, I just worry that there may be some potential problems.
    $HYPERION_HOME/common/CSS/9.3.1/lib/css-9_3_1.jar
    $HYPERION_HOME/common/utilities/CSSImportExportUtility/importexport/lib/css-9_3_1.jar
    $HYPERION_HOME/AnalyticAdministrationServices/server/lib/css-9_3_1.jar
    $HYPERION_HOME/AnalyticAdministrationServices/deployments/Tomcat/5.0.28/webapps/eas/WEB-INF/lib/css-9_3_1.jar
    $HYPERION_HOME/AnalyticProviderServices/external/css/css-9_3_1.jar
    $HYPERION_HOME/DataIntegrationMgmt/9.3.1/Resources/jars/css-9_3_1.jar
    Our HSS Patch is 9.3.1.0.11 under in Unix server.
    Regards,
    nww

    Each product/module requires the foundation (CSS) libraries. Since the product/modules are packaged at different times (ie, they are not part of a single installer package), some might be slightly different versions.
    It's not an issue to worry about.
    Nick

Maybe you are looking for

  • How to add Live Type in the external editor windows?

    I was just refreshing myself by one of the FCP dvds from magent media where Even Schechtman show his window of External Editors in System Settings. I have the latest FCP version but that line which reads "Live Type" in external editor window is missi

  • Dealer Invoice !!

    Hi In procurement from 1st stage or 2nd stage dealers is there any special customization in SPRO or its just we have to tick the MRP indicator and change excise base value during excise capture. Any help will be appreciated Thank You

  • 250$ gift card never came

    I signed up to Verizon and was promised a $250 visa prepaid card. I declined to get the cheaper rate per month in order to get this card. It has not arrived. I've called Support 3 times and get passed back and forth to different call centres. I've tr

  • Finding actual costs of hours booked in CAT2

    Hello experts, I am trying to locate the actual costs per hour that will be posted when a person enters time on a timesheet in CATS with a known activity type and cost centre. I believe the formula in the work centre calculates 'planned' costs - but

  • How to make a .jpg background transparent?

    Windows XP; using Photoshop Elements 2.0 :  is it possible to edit a .jpg so that the background (white, in this instance) can be transparent so that when I copy the part of the graphic I want and paste it elsewhere (another layer in Photoshop or Ill