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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:59:27+00:00 2026-05-24T17:59:27+00:00

I have created a minimal maven project with a single child module in eclipse

  • 0

I have created a minimal maven project with a single child module in eclipse helios.

In the src/test/resources folder I have put a single file “install.xml”. In the folder src/test/java I have created a single package with a single class that does:

  @Test
  public void doit() throws Exception {
    URL url = this.getClass().getClassLoader().getResource("install.xml");
    System.out.println(url.getPath());

  }

but when I run the code as a junit 4 unit test I just get a NullPointerException. This has worked fine a million of times before. Any ideas?

I have followed this guide:

http://www.fuyun.org/2009/11/how-to-read-input-files-in-maven-junit/

but still get the same error.

  • 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-24T17:59:28+00:00Added an answer on May 24, 2026 at 5:59 pm

    When you use

    this.getClass().getResource("myFile.ext")
    

    getResource will try to find the resource relative to the package.
    If you use:

    this.getClass().getResource("/myFile.ext")
    

    getResource will treat it as an absolute path and simply call the classloader like you would have if you’d done.

    this.getClass().getClassLoader().getResource("myFile.ext")
    

    The reason you can’t use a leading / in the ClassLoader path is because all ClassLoader paths are absolute and so / is not a valid first character in the path.

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

Sidebar

Related Questions

I have created a minimal RCP project with the Hello World example. I have
I have created a new solution with a minimal amount of code that represents
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a minimal PhoneGap app that has just this in the index.html:
I have created a minimal OS X boot stick (basically the Snow Leopard DVD
I have created a minimal installer with WixAppFolder set to WixPerUserFolder. Application installs in
I have created a new compiler for the maven-compiler-plugin. This compiler likes to look
I have a project that uses the maven-assembly-plugin to create source and binary tar
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have created a template for Visual Studio 2008 and it currently shows up

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.