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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:49:40+00:00 2026-06-08T09:49:40+00:00

I try to retrive a path of a directory where my executable jar file

  • 0

I try to retrive a path of a directory where my executable jar file is situated.
That means: I have the following structure:

 --> Application (this is a folder somewhere in my file system)
     --> application.jar (this is my java application
     --> SomeData (folder in the same directory like the application)
         --> some other folders
         ......

When I start my application.jar via command line I want to parse some files inside the SomeData folder.
In https://stackoverflow.com/a/320595/1540630 they already showed how to get the current path of a running jar file but when I execute the statement:

System.out.println(XMLParser.class.getProtectionDomain().getCodeSource().getLocation().getPath());

…I just get the following:

/.../Application/application.jar

But I just want to have:

/.../Application/

Better to say in later steps I need

/.../Application/SomeData/SomeFolder/data.xml

Can someone help me please?

  • 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-08T09:49:43+00:00Added an answer on June 8, 2026 at 9:49 am

    CodeSource.getLocation() gives you a URL, you can then create new URLs relative to that:

    URL jarLocation = XMLParser.class.getProtectionDomain().getCodeSource().getLocation();
    URL dataXML = new URL(jarLocation, "SomeData/SomeFolder/data.xml");
    

    You can’t simply do new File(...getCodeSource().getLocation().getPath()) as a URL path is not guaranteed to be a valid native file path on all platforms. You’re much safer sticking with URLs and passing the URL directly to your XML parser if you can, but if you really need a java.io.File then you can use an idiom like this to create one from a URL.

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

Sidebar

Related Questions

i want to save and retrieve image path in my application this is my
I have a quite simple doctrine entity that represent a news ; this news
I want to display pdf file in webview. I try using this code it
i'm developing an interface to retrieve a file from sharepoint. i have the following
I have an application calling a second activity using a list of objects. that
I have a small program in python that consists in one .py file plus
I have a file that I can get to with the UNC \mypath\myfile. I
I have an application ( sscce code that works here ) with a GtkTreeView
I have a few jinja template file in a path, I want to render
This is the exception that I am seeing when I try to consume a

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.