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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:38:22+00:00 2026-05-30T17:38:22+00:00

I’d like to take a xml file from my classpath to unmarshal it and

  • 0

I’d like to take a xml file from my classpath to unmarshal it and use it for testing purposes.
My problem is to get it as an InputStream.
I wrote these lines but I always get a null result.

InputStream is = getClass().getResourceAsStream("WebContent/WEB-INF/classes/testing/"+ COMPLETE_DOCUMENT + ".xml");

of course the path you see in the method argument is the one to my file.
I tried several combinations:

WebContent/WEB-INF/classes/testing/
classpath:testing/
classpath*:testing/

but I always get the InputStream = null.

I even tried to switch to

 ClassLoader.getResourceAsStream(...)

but nothing happens. I suppose the path to the resource is somehow wrong, but I can’t figure out where. From my servlet.xml I use some resource in the classpath configuring PropertyPlaceholderConfigurer or Jaxb2Marshaller just with the syntax

"classpath:folder/file.xsd"

and it works perfectly. The folder I want to load my xml from is a sibling of the one in the example above.
What am I missing?

EDIT :
I try to follow the spring ClassPathResource helper class approach and I get a strange behaviour: as I said before I already have some resources loaded from the classpath by some spring beans at the startup. If I use the path to such resources in the code suggested by dardo in as follows:

ClassPathResource cpr = new ClassPathResource("xmlschemas/lrinode.xsd");
InputStream is = cpr.getInputStream();

I Still get a FileNotFound Exception!
Of course "xmlschemas/lrinode.xsd" is a xsd I load at the startup successfully. It doesn’t work even if I use the full path to the resource, starting from the root of the application.

I’m starting to think I’m missing something trivial.

  • 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-30T17:38:23+00:00Added an answer on May 30, 2026 at 5:38 pm

    Spring provides a helper class named ClassPathResource

    So something like:

    ClassPathResource cpr = new ClassPathResource("folder/file.xsd");
    InputStream is = cpr.getInputStream();
    

    Should work, hope this helps!

    Link to API Doc:
    http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/core/io/ClassPathResource.html

    Sidenote

    Also, if you’re using it for testing purposes, might want to wire a bean mapped to the xsd.

    Might want to look into a JAXB marshaller

    http://static.springsource.org/spring-ws/site/reference/html/oxm.html#oxm-jaxb2-xsd

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am currently running into a problem where an element is coming back from
I'm parsing an XML file, the creators of it stuck in a bunch social
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I would like to count the length of a string with PHP. The string

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.