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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:07:30+00:00 2026-06-04T18:07:30+00:00

Somebody here who knows how to load a file on the tomcat server? We

  • 0

Somebody here who knows how to load a file on the tomcat server?
We are using:
Maven, JSF 2, Spring 3, Tomcat 7

I have the following Project Structure:

structure

I want to load the page.xml file!

I thought about setting a Environment Variable in the GlobalNamingResource in the server.xml of the server. But how can I access this variable in my WebApp?

Or I can use the ContextClassLoader, but if I want to load that file, I always get back null.

The problem is, that I can not use the FacesContext, because i get back null if I call FacesContext.getCurrentInstance();

Currently I had to hardcode the path to get it work. But I always have to change this path if I want to test it in eclipse or if I deploy it on the server.

@PostConstruct
public void loadMenu() {
             List<Page> pageCollection = new ArrayList<Page>();
    Page page = null;

    File xmlFile = new File(
            "C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0\\webapps\\rainstar2-webapp\\WEB-INF\\classes\\at\\beko\\rainstar2\\page.xml");

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document xmlDoc = db.parse(xmlFile);
        xmlDoc.getDocumentElement().normalize();

        NodeList pages = xmlDoc.getElementsByTagName("page");
        int size = pages.getLength();
        Node pageNode = null;

        for (int i = 0; i < size; i++) {
            pageNode = pages.item(i);
            NamedNodeMap attr = pageNode.getAttributes();
            page = new Page();
            page.setLabel(attr.getNamedItem("key").getNodeValue()
                    .toString());
            page.setRedirect(Boolean.valueOf(attr.getNamedItem("redirect")
                    .getNodeValue().toString()));
            page.setNavigationName(attr.getNamedItem("url").getNodeValue()
                    .toString());
            page.addRole(attr.getNamedItem("role").getNodeValue()
                    .toString());
            pageCollection.add(page);
        }
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
  • 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-04T18:07:32+00:00Added an answer on June 4, 2026 at 6:07 pm

    With JSF you could use the ResourceHandler. It works nice for resources under /webapp/resources. I am not entirely sure about resources under /main

        FacesContext currentContext = FacesContext.getCurrentInstance();
        ResourceHandler resourceHandler = currentContext.getApplication()
                .getResourceHandler();
        Resource resource = resourceHandler.createResource(fileName, libraryName);
    

    The libraryName is the name of the folder under /webapp/resources.

    EDIT : Without relying on JSF you could use the good old ClassLoader.

         InputStream inputStream = this.getClass().getClassLoader()  
                 .getResourceAsStream("/path/to/file/from/.war_as_root/fileName");  
    

    Please note that the path is relative from the root of your packaged .war

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

Sidebar

Related Questions

Hello is there somebody here who knows how to add temporary datas into a
Somebody knows an example of this? an application made with JSF 2.0 and EJB
I have looked around here to see if somebody has asked this question before
I have a Javascript who works well, because yesterday i get here some very
I am just hoping for somebody out there who might have an answer. I
I have some files to scan with patterns using preg_match like: File name: (a
Hopefully somebody can help me out here. I'm working within an embedded ActionScript2 and
I initially asked this on Superuser, but somebody advised me to repost here. I
somebody know what is encoding type of message that client sends to websocket server?
Somebody asked similar question not long ago. But nobody answered comprehensively. Assume I have:

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.