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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:22:49+00:00 2026-06-07T16:22:49+00:00

I’d like to run MyRunnableJar.jar from command line. It will need to read from

  • 0

I’d like to run MyRunnableJar.jar from command line. It will need to read from file_[1-4].dat, do some processing and then write to file_5.dat. All of the aforementioned data files are near MyRunnableJar.jar in the file system. For example:

  • super_directory/
    • MyRunnableJar.jar
    • data_resources/
      • file_1.dat
      • file_2.dat
      • file_3.dat
      • nested_data_directory/
        • file_4.dat
        • file_5.dat

(MyRunnableJar.jar was created by Eclipse’s Export feature.)

The reason I want to do things this way is because the application is too computationally expensive to run on my little laptop. Instead, I want to put it on a remote server (with all the big data files that it has to access) and run it there.

The problem is, I can’t figure out how to show the runnable JAR where those data files are. The data files can certainly be moved around if need be. However, keeping them inside the JAR is not an option, because if I want to change even a bit of the application code, I’d have to re-transfer the entire JAR, which would be quite large if it includes the data files. Moreover, I would be unable to write to file_5.dat if it was actually in my JAR.

I am aware that there are many questions similar to this on Stack Exchange, but in each case the question is slightly different in some important way.


EDIT:

  • Please see Accepted Answer.
  • Also note that Andre’s solution (explained in the comment) also worked, since in my case, the JAR and the data file will always be in the same position in the filesystem relative to one another.
  • 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-07T16:22:51+00:00Added an answer on June 7, 2026 at 4:22 pm

    What you really need to be able to do is figure out what directory your .jar file is in regardless of what the System.property("user.dir"); returns or where the MyRunnableJar.jar is executed from. You don’t want to have to assume that you are currently in the same directory as MyRunnableJar.jar, if you aren’t you can’t calculate the relative directory because you don’t know where you are relative to that .jar anymore.

    The following code snippet will do this for you:

    return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath());
    

    replace MyClass with your main class

    Then you can use that to build the path to the directory you want to read from. The is all cake from there.

    • 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 would like to run a str_replace or preg_replace which looks for certain words
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

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.