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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:57:37+00:00 2026-06-12T17:57:37+00:00

Possible Duplicate: Executing a shell script inside a jar file. How to extract? I

  • 0

Possible Duplicate:
Executing a shell script inside a jar file. How to extract?

I have a shell script packaged into my JAR file within the ‘engine’ package.

In my program I am running a shell command using Process and ProcessBuilder. This all works fine.

If I specify the path to the shell script on my computer then the program works fine. If however I package the shell script into my JAR and access it like this:

scriptLocation = this.getClass().getResource("/engine/shell-script.sh").toString();

And run the program, then I get the following error:

java.io.IOException: Cannot run program "file:/Users/USERNAME/Desktop/Application-Name.jar!/engine/shell-script.sh": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
    at java.lang.Runtime.exec(Runtime.java:593)
    at java.lang.Runtime.exec(Runtime.java:431)
    at java.lang.Runtime.exec(Runtime.java:328)
    at engine.Download$1.run(Download.java:39)
    at java.lang.Thread.run(Thread.java:680)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:53)
    at java.lang.ProcessImpl.start(ProcessImpl.java:91)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
    ... 5 more

I’m starting to think this cannot be done, I would very much like to provide this shell-script as part of the application, can it be done?

Thanks in advance everyone.

======== UPDATE ==========

I eventually solved this problem. Shell cannot execute scripts within a JAR bundle, it’s not about Java, but shell. I fixed this by doing the following:

Java has a createTempFile() method (with option to delete the file once the application has been terminated), invoke this, and write the file within the JAR bundle that you want to access to this temp file. You then have the shell script on the local filesystem, and are able to execute the script.

  • 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-12T17:57:39+00:00Added an answer on June 12, 2026 at 5:57 pm

    Its not about Java, its about shell. As far as I know shell interpreter can’t execute scripts that reside in the zip file. So you have a couple of options here:

    1. Read the shell script as a text file from within your java program.
      create a temporal file (in temp dir or any other relevant place and copy the content of the file there. And then call the shell interpreter with this temporal script.
      I believe its the best approach

    2. Since jar is a zip, you can unzip it from within the shell find a script and execute the shell. Again this is more awkward and rather wrong, but technically it should work.

    3. If you don’t have low level stuff in your script, you can consider to rewrite the logic to groovy script (maybe you’ll find useful groosh project).
      Then call the groovy code from the memory and not from the file.

    Well, I’m out of ideas, If I were you, I would implement the first solution 🙂
    Good luck and hope this helps

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

Sidebar

Related Questions

Possible Duplicate: Problem executing bash file I have created a bash file script and
Possible Duplicate: Executing <script> elements inserted with .innerHTML Dynamically Inserting <script> tags into HTML
Possible Duplicate: How do I determine if my python shell is executing in 32bit
Possible Duplicate: How to call one batch file after another I have a batch
Possible Duplicate: Safe executing shell scripts; escaping vars before execution I want to pass
Possible Duplicate: How may I reference the script tag that loaded the currently-executing script?
Possible Duplicate: Start background process from .bashrc I'm executing a script in .bashrc and
Possible Duplicate: Run a PHP CLI script from a webpage I have a problem
Possible Duplicate: executing assembly within a function in c++ long getesp() { __asm__(movl %esp,%eax);
Possible Duplicate: How may I reference the script tag that loaded the currently-executing script?

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.