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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:05:57+00:00 2026-06-18T00:05:57+00:00

I have a jar file which I do not have the source code but

  • 0

I have a jar file which I do not have the source code but want to use.

The jar file prompts for a file to read and generates an output file using a combinatin of the input file and a number of ‘helper’ files it uses for data. It works perfecty fine if run from its expected home directory, but I’m trying to write a script which will allow running the jar from anywhere.

The problem is that if I try running the jar file from anywhere other then its home directories it fails to find the support files it needs to properly generate its data.

If I run the file from its expected home directory I have to give the full address of the input file or it won’t find it. I would prefer to be able to give just the relative path and Java know to look at whatever directory the person calling my script is in.

Is there a way I can have a bash script pass a command line argument to Java that would ensure that this jar looks at both of the relevant directories (directory of the helper files and the current dir of the person calling the script) when trying to resolve a relative file path? Something like the -classpath argument?

  • 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-18T00:05:58+00:00Added an answer on June 18, 2026 at 12:05 am

    With the --classpath (or -cp) you can tell your Java program where it should take the dependency classes. So, probably if you do like in your files directory

    $JAVA_HOME/bin/java -cp '.:/path/to/the/original/program' My.class myfile.txt
    

    then it will wind the program, and find your files as well.

    UPDATE

    If it doesn’t work, you can try to force the file loading some other way. The Javadoc says:

    By default the classes in the java.io package always
    resolve relative pathnames against the current user directory. This
    directory is named by the system property user.dir, and
    is typically the directory in which the Java virtual machine was
    invoked.

    So, you can try running the program from the original directory this way:

    $JAVA_HOME/bin/java -Duser.dir=/path/to/the/files/directory My.class myfile.txt
    

    UPDATE2:

    As I wrote in a comment, you can try symlinks. Execute the following commands in the original directory:

    ln -s /path/to/the/files/directory datafiles
    
    $JAVA_HOME/bin/java My.class datafiles/myfile.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a compiled Java Application (.jar file extension, no source code) which will
I have a project, in which I want to invoke another Jar file in
I have a jar file that I would like to execute using PHP, but
For our Kunagi Java web application we have a signed kunagi.jar file which contains
I have the problem running executable .jar file. I've created a project which contains
I have a jar file that I want to put in the shared lib
I have a jar file and I invoke the jar using java -jar myjar.jar
I have a web application which deploys fine as an ear file. But when
In my project i have five classes but when i export jar file of
I have jar file which is signed on my local machine. Its working fine

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.