facebook

EAR file & reading a text file

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #220897 Reply

    harryajh
    Member

    I have an Enterprise application comprising 1 web comp & several EJB’s.

    From the Web component I want to read the contents of a file that will be supplied with the packaged EAR file.

    The deployment directory structure looks like this –

    I:\domains\dev\applications\MyApp\EJB1
    I:\domains\dev\applications\MyApp\EJB2
    I:\domains\dev\applications\MyApp\MyWeb

    So I thought if I put the text file in this dir –

    I:\domains\dev\applications\MYApp\MyWeb\WEB-INF\classes

    then used used FileInputStream(fileName) it would find it – wrong!

    Putting this bit of code in to see which directory it’s looking at –

    File dir1 = new File (“.”);
    try
    {
    System.out.println (“Current dir : ” + dir1.getCanonicalPath());
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }

    produced I:\domains\dev – what the heck? – this is miles outside the app dir!

    Any ideas? – must be something stupid I’m not doing!

    thanks

    harry

    #220924 Reply

    Riyad Kalla
    Member

    Harry, few things:

    1) Check the Web app spec for class loading hierarchies if you don’t want to duplicate the file from the EJB project to the web project. There is actually a scope to these modules and who can read what.
    2) Good job using “.” trick figuring out what current dir you are in
    3) Your current boot location is determined by how your application server runs your app, it will vary from app server to app server, so hard coding a path that it outside of your webroot dir is not a good idea. Try copying the resource file into your web project and using getResourceAsStream to read the file in.

    #220950 Reply

    harryajh
    Member

    thanks for that, found this article which might help others

    http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: EAR file & reading a text file

You must be logged in to post in the forum log in