JAR files reading list files

Discussion in 'Java' started by rob hadow, May 21, 2004.

  1. rob hadow

    rob hadow Guest

    I have written an application which is a kind of search engine for a book.
    I down loaded off the net the list files which contain the program listings
    for the book.
    So my application can allow a user to search for any program listing.

    The application works.However I want to put it into a JAR together with the
    lst files (list files), so that the application can be run by clicking on
    the JAR.
    I have got it run OK, but I have to have the lst files in the directory at
    which the the JAR is executed from. I can't get the application to get the
    list files from the JAR itself.

    I have the class files and the list files in a package, all contained in the
    JAR. I have used a manifest file.

    How do I get my application to look for the list files in the JAR rather
    than looking in the cuurent directory?

    I would be grateful for any suggestions! I hope my problem makes sense!

    Rob Hadow
     
    rob hadow, May 21, 2004
    #1
    1. Advertising

  2. On Fri, 21 May 2004 12:38:40 +0100, rob hadow wrote:

    > How do I get my application to look for the list files in the JAR rather
    > than looking in the cuurent directory?


    <http://www.physci.org/codes/javafaq.jsp#path>

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, May 21, 2004
    #2
    1. Advertising

  3. rob hadow

    rob hadow Guest

    Andrew

    Thanks, I,ve looked at your web site. Do I use the method
    Class.getResource(String name) ?

    File dire=new File("listing.lst"); // listing.lst is the directory
    containing the lst files
    File file=new File(dire,theFile); // theFile is a string containing the lst
    file within the directory
    FileReader fr = new FileReader(file);
    BufferedReader br = new BufferedReader(fr);

    Do I replace the first line with something like File dire=new
    File(Class.getResource("listing.lst")); // ???

    Rob Hadow


    "Andrew Thompson" <> wrote in message
    news:103j6tvavjz56$.gl3a2az01q0t$...
    > On Fri, 21 May 2004 12:38:40 +0100, rob hadow wrote:
    >
    > > How do I get my application to look for the list files in the JAR rather
    > > than looking in the cuurent directory?

    >
    > <http://www.physci.org/codes/javafaq.jsp#path>
    >
    > --
    > Andrew Thompson
    > http://www.PhySci.org/ Open-source software suite
    > http://www.PhySci.org/codes/ Web & IT Help
    > http://www.1point1C.org/ Science & Technology
     
    rob hadow, May 21, 2004
    #3
  4. On Fri, 21 May 2004 13:23:07 +0100, rob hadow wrote:

    (comments all way to bottom)

    > "Andrew Thompson" <> wrote in message
    >> On Fri, 21 May 2004 12:38:40 +0100, rob hadow wrote:
    >>
    >>> How do I get my application to look for the list files in the JAR

    ...
    >> <http://www.physci.org/codes/javafaq.jsp#path>

    ....
    > Thanks, I,ve looked at your web site. Do I use the method
    > Class.getResource(String name) ?


    Yes. You can check the JavaDocs* to see it returns an URL..
    (* Good links)
    <http://www.physci.org/api.jsp?class=java.lang.Class>

    > Do I replace the first line with something like
    > File dire= new File(Class.getResource("listing.lst")); // ???


    I think you are going in the wrong direction
    using Files. You can do more with an URL
    than a file object, so I have gotten into the
    practise of not using Files unless they offer
    a specific advantage.

    With Jar's, for example, you can get an Enumeration
    of the ZipEntries and use them to construct URL's
    through which you can use an..
    <http://www.physci.org/api.jsp?class=java.net.JarURLConnection>
    To get the data..

    HTH

    Oh, and could I ask you to 'in-line post with trimming'
    as I and some others do? It makes threads easier
    to understand.. Follow link for further details.
    <http://www.physci.org/codes/javafaq.jsp#netiquette>

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, May 21, 2004
    #4
  5. rob hadow

    rob hadow Guest


    > > On Fri, 21 May 2004 12:38:40 +0100, rob hadow wrote


    > > Do I replace the first line with something like
    > > File dire= new File(Class.getResource("listing.lst")); // ???



    > "> > "Andrew Thompson" <> wrote in message


    > I think you are going in the wrong direction
    > using Files. You can do more with an URL
    > than a file object, so I have gotten into the
    > practise of not using Files unless they offer
    > a specific advantage.
    >
    > With Jar's, for example, you can get an Enumeration
    > of the ZipEntries and use them to construct URL's
    > through which you can use an..
    > <http://www.physci.org/api.jsp?class=java.net.JarURLConnection>
    > To get the data..
    >
    > HTH
    >
    > Oh, and could I ask you to 'in-line post with trimming'
    > as I and some others do? It makes threads easier
    > to understand.. Follow link for further details.
    > <http://www.physci.org/codes/javafaq.jsp#netiquette>


    Thanks for the info. I am looking into using URLs instead of files, but am
    not getting anywhere!.

    But I am not able to import java.util.zip or java.util.jar, I
    get...............

    MyClass.java [12:1] cannot resolve symbol
    symbol : class jar
    location: package util
    import java.util.jar;
    ^
    Does this mean I don't have the classes? I have just upgraded from jdk1.3
    to j2sdk1.4.2, by downloading j2sdk1.4.2_04 and Netbeans IDE, and assumed
    all the Classes would be there. Does this mean I have a problem?

    Is what I have done "in-line trimming" ?
    Rob Hadow
     
    rob hadow, May 21, 2004
    #5
    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. Eric McIntyre

    Jar files in Jar files

    Eric McIntyre, May 24, 2004, in forum: Java
    Replies:
    1
    Views:
    506
    Roedy Green
    May 24, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    630
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,787
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,864
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    699
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page