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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:26:00+00:00 2026-05-26T14:26:00+00:00

I need to run a shell script at runtime from a WAR that I

  • 0

I need to run a shell script at runtime from a WAR that I run on Tomcat.

Thus, I’ve placed my script theScript.sh in my src/main/resources directory (because, yes, I use Maven). This directory is in the classpath, I’ve checked it.

In the code, I want to copy my script in a temp directory. So I’ve tried to get it via my ClassLoader:

URL myURL = ClassLoader.getSystemResource("theScript.sh");
if (myURL == null) {
    LOG.error("Couldn't find the resource");
}

And guess what? Yes, the “Couldn’t find the resource” keeps appearing all over the place in my logs.

Any idea what I’m doing wrong here?

My environment is the traditional Eclipse/Tomcat thing.

  • 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-26T14:26:00+00:00Added an answer on May 26, 2026 at 2:26 pm

    You don’t want to use the System cloassloader – that would typically only find resources that are part of Tomcat or the JRE.

    You want to load the resource from the classloader that was used to load your WAR file.
    There’s a couple of ways to do that, but the official way would be to get access to the ServletContext (javadoc) and call either getResource or getClassLoader().getResource on that.

    If you don’t have the ServletContext available, then you can “cheat” by using the classloader for a class that you know came from your WAR file. Something like

    this.getClass().getClassLoader().getResource("xyz");
    

    where this is your class that’s been deployed inside your WAR file.

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

Sidebar

Related Questions

I need to run a shell command asynchronously from a Python script. By this
I need to run an ant script from a shell script and if the
From within a screen session, I'd like to run a shell script that opens
Basically I need to run the script with paths related to the shell script
I need to write a shell script to be scheduled to run daily to
I need some assistance in creating a shell script to run a specific command
I have a script, that I need to run after committing to a project
i have unix shell script which is need to be run like below test_sh
My $SHELL is tcsh. I want to run a C shell script that will
I need an Eclipse Plugin run shell scripts under Linux. I have a beautiful

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.