Referencing files from classes

Hi All,
could someone help me out with the correct procedure to reference a file (not a java class) from a class? In my situation I have a directory structure for a web app of the form:
/WEB-INF/my-config.xml
/WEB-INF/classes/datautils/AppConfig.class
(the two WEB-INFs being the same directory obviously)
This structure could end up in any directory, depending on the arrangement of the webserver, or in a jar file for instance. AppConfig.class and my-config.xml will always have the same relative relationship.
I want something like:
File file = new File(***PathToFile***);
In the AppConfig class, the problem is that ***PathToFile*** changes depending on where the app is installed and where its run from in the server.
Is there a way of say finding out the path of the class AppConfig.class and then using that to construct the path to my-config.xml?
Cheers
Matt

Thanks guys,
a couple of issues though - first baddar:
There are methods in the File API to tell me where a File is once I have located a reference to it. In my case I need to know where AppConfig.class is located before I can even find the file my-config.xml and set up a File object that wraps it. So those methods don't help me.
akalex:
That method works fine in if I am using these classes in a web app and have a Servlet context to use. I want a technique that doesn't rely on the Servlet api preferably. That way I can use the AppConfig.class in other situations. The name AppConfig.class doesn't sound like a class that would be used elsewhere I know, but in another situation I may have a general class I would like to set its behaviour with a file and use in other applications.
So the question remains - is there anyway I can find out the path that a class is in when running any kind of Java app - not necessarily in a container, perhaps just on a JVM as a standalone app.
thanks chaps
matt

Similar Messages

  • Create Executeable File From .class

    Hi All,
    I want to create executable file from .class. Is there any solution so that it should create only windows Dependent executable file so that it has to use windows DLL for all api calls.
    Regards
    Srikanth Addepalli

    What he is saying is you will want to make your
    .class -> .jar first. from here you can implement a
    variety of tools like
    http://www.excelsior-usa.com/articles/java-to-exe.html
    http://www.regexlab.com/en/jar2exe/
    http://jsmooth.sourceforge.net/
    Those are all free however this one isn't
    http://www.bestvistadownloads.com/software/t-free-jar2
    exe-standard-edition-download-lmdepovu.htmlThanks for Reply.
    But Every software you specified here is indirectly using the Java virtual Machine for execution.I need a software such a way that i should run without help of JVM.
    regards
    Srikanth Addepalli

  • Is it possible to set up a new library that accesses referenced files from an old library AND retains all my Aperture adjustments

    I am moving files from one external hard drive to another, using the 'relocate originals' file command. This is very slow & tedious. Is there away to shortcut this? I was hoping to just set up a new library that would access the same files & folders on the new hard drive but this only results in preserving my original files, not all the Aperture data, the adjustments and metadata.
    Is there no better way than the 'relocate originals' file command?

    Just copy the library over to the new drive?

  • Referencing files from classpath

    Hi,
    I'm running a web application and need a way to reference a file from the classpath. I think I have to put a <resource-ref> in my web.xml file but I'm not positive.
    Does anybody have any suggestions?

    I wouldn't think you'd need anything. Just Classloader.getResource(). I certainly don't use anything else.

  • How to move referenced files from 1 EHD to another EHD

    I have an ap lib of 100,000 images/videos stored on a gdrive 2 TB. I want to move them to a Drobo 5d and don't know how. I have my aperture library set up exactly the way i have it set up on my gdrive. Do I use 2 finder windows to drag all of my projects from the gdrive to the Drobo? If so, do I also drag the aperture library folder?     If I do this how will aperture know to look for the files on the new Drobo 5d and not the gdrive?     Or do I have to go into each individual project in aperture and relocate the originals to the new Drobo 5d? This seems like it would take forever.  What I want to accomplish is to have all of my images and the metadata, geotags, edits etc associated with these images on the new Drobo 5d.  I greatly appreciate any help on how to do this.  Thank you

    A BIG thank you for all to respond. As I am not techie at all I find this process intimdating bc I have worked so long to create large ap lib i currently have. I have spent the last week reading and re-reading many posts and tips from this site and the ap manual. I am curently running a repair of library permissions and whenever that finishes i am going to relocate my originals to the new EHD (drobo 5d).
    So, there is one thing I am confused about. I will go to photos ( 115,000)   select all    go to file, relocate masters.  Now, the scary part for me: How do I ensure that the same project structure I currently have in aperture gets "relocated" to the new EHd?  For example, in my library I have 1660 projects of which 90 percent are organized as 2013_06_07 , 2013_06_06, etc  the remaining 10 precent are by names, ex Vacation Ireland 2012. i also have various albums.  In the relocate origianls menu how do I ensure that they relocate in the same structure? I dont know which options to choose
    ? Subfolder? Custom subfolder? Name format? Custom name?
    I just want all the images to move over with all their keywords, geotages, ratings, etc and staye in the same projects they are currently in.
    I fear that you have already answered this for me and i have failed to fully understand....thank you

  • Aperture 3 doesn't see Network Drive that holds masters of referenced files

    Hi
    I created a new referenced library with about 35000 images and for the few days it worked fine. The Referenced files are located on a Drobo that is connected to My Mac OS X server. I connect to it Via AFP.
    About 2 days ago, I opened the library and the library does not see the referenced files. When I choose a file and select 'Locate referenced Files from the File menu, the locate window pops up and it shows the Drobo as being offline, even though I have mounted it, and outside of Aperture, I can access it and use it - it is definitely mounted. the "Mount" button is greyed out in the Locate referenced files window, and when I select the file using the file browser in this window, which I am able to do even though Aperture Shows the Drobo as Offline Volume Status section above, the "reconnect button remains greyed out.
    I have rebuilt the library, rebooted the server, unmounted and remounted the Drobo, and no matter what I do, it does not see the referenced files.
    Can anyone help me recoonect these files?

    I am having the exact same problem in Aperture 3.0.2. Aperture says that 529 files in a particular library are "offline" when they are on a mounted volume. The external volume on which they reside is very much ONLINE despite the fact that Aperture says it is offline.
    In fact that same volume shows up in the bottom half of the window that pops up when you select the files in Aperture and choose "Locate referenced files". I was able to successfully reconnect several thousand files by simply navigating to the files that Aperture identified as "offline" in the bottom window. But these 529 (out of a total of 4266) won't reconnect and in the bottom window the pixel dimensions for the file I'm trying to reconnect are missing. If I navigate to the files in the Finder the pixel dimensions are shown. I was able to reimport some of the so-called "offline" files on the "offline" volume. There were originally 572 that would not reconnect, and I reimported 43 of them, leaving me with 529 that should be connected, but aren't.
    Last week I spent several hours on the phone with the tech support team at Apple, but they so far have been unable to help me solve this problem. I could just reimport the files, but then would have to lift and stamp adjustments for all 529 files and get rid of the "offline" masters. One of the tech support people was going to research whether it might be possible to somehow do a "force reconnect", but hasn't gotten back to me about this.
    The external volume on which these files reside is an OWC Qx2 which is a 4.5 GB Raid 5 connected via firewire 800. In addition to being completely accessible outside of Aperture, I have run Disk Utility on it, and it verifies.
    I am hoping that Apple will come up with a fix for this problem soon.

  • How to delete referenced file on network storage

    When I try to use the "delete master image and all versions" and check the "move referenced files to trash" I get an error saying that aperture doesn't have permission to move the file to the trash. I don't understand as I am opening the network volume with read/write permissions. I can delete from the finder so I don't understand why aperture can't do the same. I need to be able to delete referenced files from Aperture. I guess I "just don't get it".

    You could relocate the master, within Aperture, to a local disk. And then delete >>it.
    Yes, but that's where it becomes a real issue. When I decide to delete an item I have to do each one manually. That's a real pain.
    What I am doing is moving new projects local until I sort them out and then move the masters to the network drive.
    It would be great if Aperture really fully supported all functions on the network store. Especially since finder can do it without difficulty.
    Thanks for your time and input.
    Fred

  • Locate referenced files for whole library?

    Hello,
    I have a referenced library (internal drive, iMac) with Masters (on an external drive). I made a back-up duplicate (finder copy) of that Masters volume, on another drive. Now I'm working from that duplicate copy of "Masters" (same name, spelling, as original "Masters", on a separate external drive).
    How do I reconnect all 60,000 referenced files (from the duplicate "Masters" drive) with my library (on the iMac). I know how to do them one file at a time from the Aperture library (File > Locate Referenced Files) but can not figure out how to reconnect everything in one or two easy clicks.
    Help!
    Thanks!
    Patrick

    Select a batch of images, and go into +Locate Referenced Files+ - just the same as doing one at a time. Match up one image from your batch with the file and then, instead of hitting the <Reconnect> button, hit the <Reconnect All> button.
    Do a small batch initial until you get the hang of it, and then make a bigger selection and go and have a cup of tea...
    Here's an [earlier description|http://discussions.apple.com/message.jspa?messageID=11334896#113348 96] I gave of this process with some background details of how I handled it first time around.
    Hope this helps.
    Regards,
    Gary

  • Aperture, Droboshare, and referenced files

    Hi, I just bought Aperture 3.0.2 as an upgrade from using iPhoto. My iPhoto setup is such that I have all my files stored on a Drobo and connected to my network via a Droboshare. I am attempting to have my Aperture Library file stored on my macbook, while creating reference files of the same photos on the Drobo.
    Now, I have no problems accessing the photo using iPhoto, but when I tried to import the same photos as referenced files in Aperture and leaving the files stored on the Drobo, it initially finds the files in the Import tool, creates thumbnails, and then proceeds to display blurry thumbnails of the pictures.
    When I double-click into the picture, it shows the image enlarged and blurry. If I select Show File in Finder, it proceeds to tell me the file cannot be found and has possibly moved, even though the file remains in the Drobo unmoved. Outside of Aperture, I can still access the file and iPhoto still has no problems seeing the image.
    In Aperture, if I select Locate Referenced Files, the bottom half of the window I can traverse the tree and I can see the file, but clicking Reconnect does not do anything.
    Does anyone have any luck setting up Aperture to use referenced files stored on a Drobo connected to the network via a Droboshare?
    Any help is appreciated.
    Thanks,
    Tim

    hmm, well i did try using referenced files directly off my machine and that seemed to work. Thing is, iPhoto is working fine with the Drobo via the Droboshare, as is my iTunes, which I also store on the Drobo as well, so I assume the problem must be Aperture which doesn't seem to like the Drobo?
    After importing a referenced file from Drobo into Aperture, I did notice a peculiarity: when I click Show in Finder in Aperture, it says the file cannot be found, and it displays the following path:
    /Volumes/DroboShare/0db090320629/LUN0/Drobo/0db090320629/LUN0/Drobo/flowers.jpg
    so I copied the following path into the Finder's Go To Folder:
    /Volumes/DroboShare/0db090320629/LUN0/Drobo/0db090320629/LUN0/Drobo
    and the Finder says the folder can't be found.
    However, I noticed the path is repeating itself after the first Drobo, so then I tried copying the following path into the Finder's Go To Folder:
    /Volumes/DroboShare/0db090320629/LUN0/Drobo
    and this works and Finder can find the folder where the image is stored. This leads me to believe there is a bug in the way Aperture is creating the referenced image path?
    Shortly after I originally posted, Apple released 3.0.3. I was really hoping this would fix the error, but I can confirm I still have the same problem after upgrading to 3.0.3.
    I'm just curious if anyone else out there is successfully using a workflow which incorporates a network attached storage for their referenced files?
    Regards,
    Tim

  • Referenced Library from an Eclipse plugin needs a .properties file

    I have a problem with reading .properties files from my Eclipse plugin.
    My plugin uses a Referenced Library .jar file. In the file a class is calling:
    new FileInputStream("xxx.properties")
    and it can't find the .properties file. I have this file. Where should I put it, or include it's path so that my library can find it when running the plugin?

    Place it in the working directory.And what would be the working directory for a plugin?Probably the same as for Eclipse since it's loaded by that process.

  • Getting file from directory where class files are

    hi i want to load a properties file from the directory where my java program is (the class/jar files)
    somebody told me that i could use System.getProperty("user.dir"); but it would only work under windows; under linux it points elsewhere.
    how can i determine the directory where my program lies? sounds easy but i failed :(

    why to hell put it in the classpath? Because that way you don't have to ask the user where the hell he put the file.
    and if i would do so the next question: how can my
    program modify the classpath?It can't. And it doesn't need to.
    isn't there another way to determine the directory
    where the app is started from???If you mean the current, or working, directory, then yes there are several ways to determine that. But that directory need not be where the classes are actually stored. In fact the current directory doesn't even have to be in the classpath.
    Now, here's the best way to deal with properties files. (IMHO of course.) Put them in the classpath, in the same directory or jar file as your classes. Then to create a Properties object and load it from your properties file named e.g. "default.properties" you do this:Properties props = new Properties();
    props.load(this.getClass().getResourceAsStream("/default.properties"));

  • Cannot Retrieve referenced URL in wscript file from Local System Account, but not other accounts on the computer.

    Hello,
    I have a WScript File that includes an external resource (js file).
    It works on one computer and it does not work on another computer.
    If I run this file from a normal admin command prompt everything runs fine on both computers.
    If I run this file from the Local System account using PsExec it runs fine on one of the computers and throws an error "Cannot Retrieve referenced URL" on the other computer.
    The reason I want it to run from the Local System account is that it is executed from a Windows Service.
    Is there some setting or some way for the IE cache to get corrupt on the Local System account or something like that?

    JRV,
    You are by far the worst 'support' person I've ever seen. If you aren't going to be thoughtful in providing support, don't pretend. If you're going to pretend, leave your condescension on the shelf. You have provided no thoughtfulness whatsoever to his issue,
    and have in no way improved the discourse. You are arrogant and condescending without exhibiting any intelligence whatsoever. I'm impressed Matt kept calm through your demeaning, counterproductive diatribes.
    Matt,
    First I'd check UAC settings, because I believe that can change how elevation works substantially.
    Second, I would check the versions of wscript.exe on both machines, both in System32 and SysWow, and I'd check for updates bypassing WSUS to make sure there's not something silly going on there (totally a shot in the dark, catch-all theory).
    Have you made any headway in the last few weeks?
    -John
    This is not a support forum and it is not for assistance in fixing broken configurations.  It is a scripting forum. The OP proved that the issue is not the script but the environment it is running in.  You should not get mad just because you are
    not getting satisfaction.
    ¯\_(ツ)_/¯

  • How to restrict the .class file from decompilation

    Hi all,
    i got a security problem. i need all the java class files to be most secured. is there any to restriction on the java class files from decompilation. is that possible?. pls help me out. it's very urgent
    thanks in advance

    You can make it harder to understand the decompiled code if you use an obfuscator. (I don't have links to any, do a google search, or search these forums, it have been discussed here previously.)
    You cannot completely prevent decompilation, though. Obfuscating does not for example not mean that any passwords you have hardcoded in the source is secure.

  • Running the .class file from java code

    I'm doing a kind of providing service like compiling and running Java code on server side and giving output to the end user.
    Please suggest me an approach with code to run .class file from the Java code.
    import java.io.*;
    public class demo {
    public static void main(String args[]) throws IOException, InterruptedException {
    int result;
    try {
    System.out.println("command output:");
    Process proc = Runtime.getRuntime().exec("java -cp . demoh");
    InputStream in = proc.getInputStream();
    result = proc.waitFor();
    BufferedInputStream buffer = new BufferedInputStream(proc.getInputStream());
    BufferedReader commandOutput = new BufferedReader(new InputStreamReader(buffer));
    String line = null;
    System.out.print(commandOutput);
    try {
    while ((line = commandOutput.readLine()) != null) {
    System.out.print(line);
    System.out.println("command output: " + line);
    }//end while
    commandOutput.close();
    } catch (IOException e) {
    //log and/or handle it
    }//end catc
    } catch (IOException e) {
    System.err.println("IOException raised: " + e.getMessage());
    }

    What happened when you tried what you have there?

  • Aperture referencing files to time machine HD instead of from 'working' HD

    Every once in a while I will go into a project see the "broken link" icon on my previews. In Finder I check the location I have all my images stored (and initially referenced) on an external HD. They are there.
    I go to File>>Locate Referenced Files and see the referenced images have been changed to a location on my separate Time Machine external HD. I locate them and everything is fine but it's annoying.
    I don't not have Time Machine on automatic because I have a laptop and like to choose when it backs up. I've looked through other Time Machine/Aperture problems and couldn't find anything. Does any one know of a setting, advice, or have experienced this at all?
    Thanks.

    Thanks. Sorry, for the delay to answer your questions:
    I'm the only one managing the files, and it has happened quite a few times now. The files are in multiple projects ranging from recent imports to projects from a few years ago.
    I didn't need to use "File→Relocate Master ..." just the "File→Locate Referenced Files" because my masters are still intact on my working HD. It says that my previous location was on "Volumes/Time Machine/photography/...etc." when I always import masters to "Volumes/My book/photography/...etc"
    Does Aperture notice if I move master files because my thought is that Aperture is noticing my TM copying files to another HD and then referencing those instead of my original working HD I import to. Then, the next time I open Aperture it cannot reference the Time Machine files.
    Is it because I have TM (USB) backing up my internal HD and my external working HD (FW800)?

Maybe you are looking for

  • After upgrading to Itunes 7.2, it won't launch without crashing

    Itunes was working fine on my pc. When I opened it, it prompted me to install an updated version of Itunes and Quicktimes. I followed the prompts and installed it. After it installed, I launched Itunes and it crashed with "Itunes has encountered a pr

  • EPS files placed in InDesign can't be saved in Photoshop until the ID document is saved

    Hi! I'm wondering if there's a way around this problem. When mounting an EPS images in InDesign that image can't be saved in Photoshop until the InDesign document has been saved. Is there a workaround for this problem? It doesn't happen with TIFF fil

  • Steps Involved in creating Users thru the API

    Hi Mark or anybody from Oracle, Your solution to build a string for the XML and then parse it is ok. However I would like to do it programmatically instead of building strings containing the XML. What are the steps and exactly what attributes do you

  • What is br class="clearfloat" / doing in my code?

    I'm using Dreamweaver and am assuming that at some point DW put this code in for some purpose because I don't remember adding it. My question is, do I need this line and if so is there some place else I can put it so that it doesn't add the extra spa

  • Error Installing iTunes 7.6

    Hey All. Started to update my iTunes 7.5 to 7.6 and i got this error There is a problem with this windows installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor I have tri