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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:52:07+00:00 2026-05-27T04:52:07+00:00

You can run a scala script as a linux shell script: #!/bin/sh exec scala

  • 0

You can run a scala script as a linux shell script:

#!/bin/sh
exec scala "$0" "$@"
!#

println("Hello")

In one such script I need to load classes from a group of jars (which happen to be in the same directory as the script). If this were the REPL I could use :jar, but that’s not available in script mode.

I’m trying to set the -classpath parameter:

#!/bin/sh
exec scala -classpath '.:./*.jar' "$0" "$@"
!#

import javax.media.jai.{JAI, RenderedOp}

but the compiler just can’t find the classes:

error: object media is not a member of package javax
import javax.media.jai.{JAI, RenderedOp}
             ^

How do I include these jars?

  • 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-27T04:52:08+00:00Added an answer on May 27, 2026 at 4:52 am

    For some reason, the glob (*.jar) wasn’t working. I was able to get the script running by putting in all the libraries by hand:

    #!/bin/sh
    exec scala -cp lib/jai_codec.jar:lib/jai_core.jar:lib/mlibwrapper_jai.jar $0 $@
    !#
    
    import javax.media.jai.{JAI, RenderedOp}
    

    I don’t know why the glob isn’t working though.

    Note that in this case I don’t have the . in the classpath because the script itself is provided as an argument. In many cases though you will need to include it:

    exec scala -cp .:lib/jai_codec.jar:lib/jai_core.jar:lib/mlibwrapper_jai.jar $0 $@
    

    Based on this helpful post, I have a script header that pulls in every jar in a lib folder, even if the script (or the folder it’s in) are symlinks.

    #!/bin/sh
    L=`readlink -f $0`
    L=`dirname $L`/lib
    cp=`echo $L/*.jar|sed 's/ /:/g'`
    /usr/bin/env scala -classpath $cp $0 $@
    exit
    !#
    
    • The first line turns the given script location $0 into its actual location on disk, expanding symlinks.
    • The second line removes the script name and adds /lib
    • The third line creates a cp variable with all the jars separated by :
    • The fourth line runs scala, wherever it may be.
    • The fifth line exits. This probably isn’t necessary, but it makes me feel better.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One can write scripts in Scala. So you can put this into Hello.scala #!/bin/sh
I need to make sure that user can run only one instance of my
Under Windows, I can run a Scala script from a different directory using a
I can run commands like vacuumdb, pg_dump, and psql just fine in a script
Let's say I have this Hello.scala. object HelloWorld { def main(args: Array[String]) { println(Hello,
When I run my Scala hello world application, like package pack object App {
I have a sh script (scala compiler). I'm trying to run it from Terminal
Can command java run a compiled scala code? If so, why do we have
I can run the server on my local machine and connect to it on
I can run this command in SqlManager to detach the db ALTER DATABASE mydb

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.