Changes between Version 7 and Version 8 of UsingResources

05/24/13 11:30:33 (6 years ago)



  • UsingResources

    v7 v8  
    1 = Using resources = 
     1= Using resources in Java = 
     2Resources are data files that are needed by some application, and that are more or less static. (So normal input files are not reources) Think of icons, images, 
     3configuration files, etcetera. The main problem with resources is to store them in a place where the application can find them, in particular when it is not 
     4running on the system of the developer of the application, including webstart or jar-based deployment. So, using absolute file paths like: C:\myjavaapps\projectXYZ\data\config.xml, 
     5referring to some absolute directory on your hard disk is a bad idea. Relative pathes like ../data/config.xml are somewhat better, since you can relocate your project as a whole, including the data.  
     6But it still cannot handle web or jar deployment. A better solution is to place resource data in some place that can be found by Java method like “getResourceAsStream”. Such methods search for resource directories on the 
     7Java classpath. In particular, when an application runs from a jar file, that jar file is (automatically) on the classpath. This leads to the following solution: 
     8 * A project must have a resource (sub)directory, alongside subdirectories like src, etcetera. 
     9 * The resource directory is automatically on the class path when running the project’s applications. 
     10 * When releasing the project (using e.g. ant nbuild, ant release), the contents of the resource directory will be packaged within the project’s jar file, together with the class files. 
     11 * Resource files should be read exclusively via methods like getResourceAsStream. 
     12The hmi.util package includes a few helper classes for applying this pattern. 
     15= Outdated: resource setup in Elckerlyc = 
    216For now, see `Hmi\HmiUtil\docs\report\HmiUtilReport.tex` for an explanation.