- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
classpath for #! script
Can someone tell me how to specify the classpath or sourcepath for a #! script (on Linux)? Thanks.
--Russ P.
--Russ P.
Copyright © 2013 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland
Re: classpath for #! script
1)
export CLASSPATH=whatever
./thescript
2)
CLASSPATH=whatever ./thescript
3)
Alter the script so that wherever it passes a classpath into java or scala, it does so via their -classpath switch.
2009/2/6 Russ Paielli <russ [dot] paielli [at] gmail [dot] com>
Re: classpath for #! script
Here's the situation. I wrote a few .scala files, including a couple of #! scripts that I am using as test drivers that import some of the other files. When the files are all in one directory, I can run the scripts by just typing their names. However, I decided to create a subdirectory called "test" to keep the test scripts separate from the other files. When I go to the test directory and type the name of a script, the imports no longer work.
I tried your suggestion of typing
> CLASSPATH=.. myscript.scala
but that didn't work. I also tried the absolute path instead of "..", but that didn't work either.
I also set the CLASSPATH in my .bashrc file and sourced it, but that didn't help either.
As for your alternative 3, I do not understand what it means.
Sorry for being so dense, but I cannot find answers to these basic questions online or in the Odersky book. Any additional help will certainly be appreciated.
On Fri, Feb 6, 2009 at 1:28 AM, Ricky Clarkson <ricky [dot] clarkson [at] gmail [dot] com> wrote:
--
http://RussP.us
Re: classpath for #! script
Try starting the script with
#! scala -classpath /path/to/script/dir/
It's better to use an absolute path for this than '..', because it
doesn't make assumptions about what the current directory is when you
invoke the script. (The really bulletproof way is to get the directory
by using a shell script to get the parent directory of $0, but you
can't fit that into a #! line.)
—Jens
Re: classpath for #! script
#!/bin/sh
exec scala "$0" "$@"
!#
Where should I put the line you suggested?
On Fri, Feb 6, 2009 at 12:49 PM, Jens Alfke <jens [at] mooseyard [dot] com> wrote:
--
http://RussP.us
Re: classpath for #! script
exec scala -classpath /path/to/classes "$0" "$@"
!#
On Fri, Feb 6, 2009 at 1:03 PM, Russ Paielli <russ [dot] paielli [at] gmail [dot] com> wrote:
Re: classpath for #! script
On Fri, Feb 6, 2009 at 1:09 PM, Jorge Ortiz <jorge [dot] ortiz [at] gmail [dot] com> wrote:
--
http://RussP.us
Re: classpath for #! script
2009/2/6 Russ Paielli <russ [dot] paielli [at] gmail [dot] com>
Re: classpath for #! script
It's called "scalarun" and it allows you to write scripts such as,
#!/usr/bin/env scalarun
# REQUIRE files("lib/*.jar")
# REQUIRE artifact("org.slf4j:slf4j-api:jar:1.4.3")
# REQUIRE artifact("org.slf4j:slf4j-log4j12:jar:1.4.3")
# REQUIRE artifact("log4j:log4j:jar:1.2.15")
!#
import org.slf4j.LoggerFactory
val logger = LoggerFactory.getLogger("test")
logger.info("Hello, world!")
I'm attaching here in the hope that others might find it useful. The script is self-documenting and works only on *NIX systems I presume.
cheers,
alex