Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9141425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:38:34+00:00 2026-06-17T09:38:34+00:00

Synopsis Given the following (abridged) code that lives server-side on a servlet (Tomcat is

  • 0

Synopsis

Given the following (abridged) code that lives server-side on a servlet (Tomcat is the container). This is a GWT application, though that should be irrelevant (I think).

ServletContext context = getServletContext();
String dataFilePath= context.getRealPath("/WEB-INF/dir/dataFile.txt");
File dataFile = new File(dataFilePath);

TestCaseGenerator testCaseGenerator = new TestCaseGenerator(dataFile);
testCaseGenerator.generateTestCase();

TestCaseGenerator is a class from a jar in the project’s war/WEB-INF/lib folder, that’s been added to the GWT project as an external library.

The Problem

When testCaseGenerator.generateTestCase() gets executed, it’s unable to use dataFile to create a new LineNumberReader(new FileReader(dataFile));, a FileNotFoundException gets thrown.

I’ve verified that the String value of dataFilePath is correct and contains the proper real path to the file on the server I need to read from, as well that dataFile isn’t null. I’ve also verified that TestCaseGenerator runs just fine when called from a command line, outside of this GWT application.

I’m not sure why TestCaseGenerator isn’t able to use the File object I pass it, considering I’m passing it the real file path of the file. I can come up with some alternative solutions to get around this issue, but now I’m genuinely curious why it isn’t able to find the file.

Thanks in advance for any insight.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:38:35+00:00Added an answer on June 17, 2026 at 9:38 am

    Solved

    I foolishly neglected to include the dir/dataFile.txt in my build.xml‘s war target, so in fact the file wasn’t being included in the war package, and thus never placed within the Tomcat container.

    <include name="dir/**" />
    

    And I also misunderstood what context.getRealPath("/WEB-INF/dir/dataFile.txt"); actual returns;. From ServletContext javadoc

    Gets the real path corresponding to the given virtual path. For
    example, if path is equal to /index.html, this method will return the
    absolute file path on the server’s filesystem to which a request of
    the form http://://index.html would be
    mapped, where corresponds to the context path of this
    ServletContext.

    So even though getRealPath returns a path value, it doesn’t necessarily mean the file is at that actual path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brief synopsis, this code works beautifully and does what it is supposed except with
The brief synopsis is that I would like to have my Windows 8 application
I was trying to make the simple server code work: /* NAME: udpServer0 SYNOPSIS:
Synopsis : When calling an executable that links to shared libraries from Java code
Assuming I have this code (simplified from Synopsis ) {-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies,
Synopsis Given a type with a variadic template constructor that forwards the arguments to
Question Synopsis Given a std::vector<T> , how can I create a view that exposes
I would like to translate the following Unix 1 Liner to PowerShell. Synopsis of
How can you pick pages from a PDF file? Pseudo-code synopsis pick-pages 1,2-69,70-73,100 example.pdf
A brief synopsis of the situation: I have a service that takes information in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.