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 6199761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:14:45+00:00 2026-05-24T04:14:45+00:00

I need to access the resource files in my web project from a class.

  • 0

I need to access the resource files in my web project from a class. The problem is that the paths of my development environment are different from the ones when the project is deployed.

For example, if I want to access some css files while developing I can do like this:

File file = new File("src/main/webapp/resources/styles/some.css/");

But this may not work once it’s deployed because there’s no src or main directories in the target folder. How could I access the files consistently?

  • 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-05-24T04:14:46+00:00Added an answer on May 24, 2026 at 4:14 am

    You seem to be storing your CSS file in the classpath for some unobvious reason. The folder name src is typical as default name of Eclipse’s project source folder. And that it apparently magically works as being a relative path in the File constructor (bad, bad), only confirms that you’re running this in the IDE context.

    This is indeed not portable.

    You should not be using File‘s constructor. If the resource is in the classpath, you need to get it as resource from the classpath.

    InputStream input = getClass().getResourceAsStream("/main/webapp/resources/styles/some.css");
    // ...
    

    Assuming that the current class is running in the same context, this will work regardless of the runtime environment.

    See also:

    • getResourceAsStream() vs FileInputStream

    Update: ah, the functional requirement is now more clear.

    Actually I want to get lastModified from the file. Is it possible with InputStream? –

    Use getResource() instead to obtain it as an URL. Then you can open the connection on it and request for the lastModified.

    URL url = getClass().getResource("/main/webapp/resources/styles/some.css");
    long lastModified = url.openConnection().getLastModified();
    // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to access RMI methods from a client front end. For different reasons,
I have some resource files that are in the classpath of my web application
I need to access a network resource on which only a given Domain Account
I can't create a NT account for everyone that need access to the reports.
I need to access some members marked internal that are declared in a third
I need to access the bluetooth network interface from Java. All local network interfaces
I need to access a mysql database from c# code but I would prefer
I have two C DLLs that I need to access in the same executable.
I currently started working on a maven web-app project that needs to be launched
I have a license file that I need to access at runtime in order

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.