how to use resources in jar

Discussion in 'Software' started by daniele, Oct 17, 2007.

  1. daniele

    daniele

    Joined:
    Oct 17, 2007
    Messages:
    1
    hi,
    i have a jar file with 2 reosources, when i use the reosources in jar file it's all ok.
    If i import the file jar as library and use it in a new file Prova i recive the following message:

    ERRORE: '/home/gianni/workspace/Prova/file:/home/gianni/JfuzzyLogicFML.jar!/net/sourceforge/jFuzzyLogic/fml2fcl.xsl (No such file or directory)'.

    i have duplicate path and i don't get resources right....

    how can do to work right?

    public class Resources {

    this is the class that manage resources;

    public enum ResourceName{
    fmlSchema,
    xslt,
    }

    /**
    * @uml.property name="properties"
    */
    private static final String resourceName[] = new String[]{
    "fmlSchema.xsd",
    "fml2fcl.xsl"
    };

    /**
    * @uml.property name="singleton"
    */
    private static Resources singleton;

    /**
    * @throws Exception
    */
    public static Resources getInstance() throws Exception {
    if (singleton == null) {
    synchronized (Resources.class) {
    if (singleton == null) {
    singleton = new Resources();
    }
    }
    }
    return singleton;
    }

    /**
    * Constructor
    *
    * @throws Exception
    */
    private Resources(){
    mapResources = new HashMap<ResourceName, File>();
    }

    Map<ResourceName, File> mapResources;

    public File getResource(ResourceName name){
    File file;

    file = mapResources.get(name);
    if( file == null ){
    file = new File( getClass().getResource(resourceName[name.ordinal()]).getPath());
    mapResources.put(name, file);
    }

    return file;
    }

    }


    and here i s where i use it:
    public static FIS loadFML(String fmlFilePath, boolean verbose) throws SAXException {
    FMLValidator validator = new FMLValidator();

    File xml = new File(fmlFilePath);

    File fmlSchema = resources.getResource(Resources.ResourceName.fmlSchema);


    File xslt = resources.getResource(Resources.ResourceName.xslt);

    validator.validate( xml , fmlSchema.getPath());

    String fclDefinition = FML2FCLTransformation.transform( xml , xslt);
    System.out.print(xslt);
    return createFromString(fclDefinition, verbose);

    }
     
    daniele, Oct 17, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Splibbilla
    Replies:
    1
    Views:
    697
    Leonidas Jones
    Dec 13, 2004
  2. zutroi
    Replies:
    2
    Views:
    449
    Hendrik Maryns
    Aug 22, 2005
  3. Keld Landin-Petersen

    Jar Jar in Return of The Empire!

    Keld Landin-Petersen, Sep 28, 2004, in forum: DVD Video
    Replies:
    14
    Views:
    728
    Hugh Candlin
    Oct 20, 2004
  4. Keld Landin-Petersen

    Jar Jar in Return of The Empire!

    Keld Landin-Petersen, Sep 28, 2004, in forum: DVD Video
    Replies:
    0
    Views:
    528
    Keld Landin-Petersen
    Sep 28, 2004
  5. bluefenix

    Jar Tool - How do you use it?

    bluefenix, Jan 6, 2012, in forum: Computer Support
    Replies:
    1
    Views:
    1,028
    gladysbus
    Feb 12, 2012
Loading...

Share This Page