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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:55:38+00:00 2026-05-25T16:55:38+00:00

I have a small maven application, it loads an xml file from the classpath

  • 0

I have a small maven application, it loads an xml file from the classpath and does some manipulation. It runs fine from eclipse, but when I run maven:assembly, and get an executable jar with dependecies, the program executes up to the point where it needs to get the xml file, and then it gives:

    java.io.FileNotFoundException: /home/ubuntu/Documents/workspaces/workspace-sts-2.7.2/test/target/file:
/home/ubuntu/Documents/workspaces/workspace-sts-2.7.2/test/target/test-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/test.xml (No such file or directory)

the test.xml file is most certainly in the jar, and like i said, it runs and finds the file just fine when running from eclipse. I believe the manifest file is setup correctly:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: ubuntu
Build-Jdk: 1.6.0_26
Main-Class: org.test.test1.App
Class-Path:.

here is the code that loads the xml file:

  //load xml file from classpath
  DocumentBuilder builder = factory.newDocumentBuilder();
  ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  URL classpathFileLocation =                 
        classLoader.getResource("test.xml");
  File file = new File(classpathFileLocation.getFile());
  Document doc = builder.parse(file);
  • 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-25T16:55:38+00:00Added an answer on May 25, 2026 at 4:55 pm

    Try changing this:

    URL classpathFileLocation = classLoader.getResource("test.xml");
    File file = new File(classpathFileLocation.getFile());
    

    to this:

    InputStream is = classLoader.getResourceAsStream("test.xml");
    Document doc = builder.parse(is);  // Or look at the builder API to see what accepts InputStream
    

    I don’t know if it makes any difference, but I would use the class loader for the current class.

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

Sidebar

Related Questions

I have small utility that does some processing on a file and changes the
I have a spring application that has configured log4j (via xml) and that runs
I have a small maven project that build a java jar file. I added
I have a small command line utility project that I'm using Maven to manage.
I have small problem with my .net 2.0 winforms application. I want to embed
I have small question about pdp-11(simulator), I have this command (it begins from the
I have small project consisting of one maven project and two maven modules. One
I have small application that is uploading pictures to another website via webservice. My
I have small application using JSF 1.1. It is using NTLM for authentication. What
I have configured a Maven build for a very small GWT project I'm having.

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.