- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Prepend a directory to Java bootclasspath
Wed, 2012-02-08, 07:42
Hi All,
for testing purposes, I need to override some core Java classes.
My classes are in the directory .
In a pure Java environment it can be done using "java -Xbootclasspath/p: ..." option.
But how to do that if running a Scala program?
Unfortunately we don't have the "prepend" ("/p")option for manipulating Java bootclasspath. And in
the "-javabootclasspath" option the whole path must be specified, which is pretty long, and I don't
know how to get its content from withing a script that runs the Scala program.
I already tried to add "Xbootclasspath" option directly into the Scala starting script:
"%_JAVACMD%" -Xbootclasspath/p:"" %_JAVA_OPTS% %_PROPS% -cp "%_TOOL_CLASSPATH%"
scala.tools.nsc.MainGenericRunner %*
(scala.bat / Scala 2.9.1 / Windows XP)
But in this case the Java replacement classes get ignored.
Perhaps someone has a solution?
--
EL
Wed, 2012-02-08, 13:31
#2
Re: Prepend a directory to Java bootclasspath
Yes, thank you.
But it's so convenient to quickly test a code snippet via "-e" option or in the REPL!
It would be nice to have a solution for the scala starter script (which implies the use of
MainGenericRunner).
On 2012-02-08 09:38, Alec Zorab wrote:
> A scala program is, ultimately, just a bunch of .class files. You can
> just call your main class directly, and skip the MainGenericRunner
Wed, 2012-02-08, 16:41
#3
Re: Prepend a directory to Java bootclasspath
On Wed, Feb 8, 2012 at 04:41, Eugen Labun wrote:
> Hi All,
>
> for testing purposes, I need to override some core Java classes.
>
> My classes are in the directory .
> In a pure Java environment it can be done using "java
> -Xbootclasspath/p: ..." option.
>
>
> But how to do that if running a Scala program?
Have you tried the traditional -J-Xbootclasspath/p:?
Wed, 2012-02-08, 17:11
#4
Re: Prepend a directory to Java bootclasspath
On 2012-02-08 16:31, Daniel Sobral wrote:
> On Wed, Feb 8, 2012 at 04:41, Eugen Labun wrote:
>> Hi All,
>>
>> for testing purposes, I need to override some core Java classes.
>>
>> My classes are in the directory.
>> In a pure Java environment it can be done using "java
>> -Xbootclasspath/p: ..." option.
>>
>>
>> But how to do that if running a Scala program?
>
> Have you tried the traditional -J-Xbootclasspath/p:?
Yes. My overrides are ignored by scala in this case, too.
Tested as:
scala -J-Xbootclasspath/p:"./classes" -e "println(\"a\"(1))"
(I see that that the original Java classes from rt.jar are used here, since my override of the
java.lang.StringIndexOutOfBoundsException, which is thrown here, doesn't fill in the stack trace)
An equivalent Java program, started with
java -Xbootclasspath/p:"./classes" Test
works as expected (i.e. my version of StringIndexOutOfBoundsException gets thrown).
A scala program is, ultimately, just a bunch of .class files. You can
just call your main class directly, and skip the MainGenericRunner
On 8 February 2012 06:41, Eugen Labun wrote:
> Hi All,
>
> for testing purposes, I need to override some core Java classes.
>
> My classes are in the directory .
> In a pure Java environment it can be done using "java
> -Xbootclasspath/p: ..." option.
>
>
> But how to do that if running a Scala program?
>
> Unfortunately we don't have the "prepend" ("/p")option for manipulating Java
> bootclasspath. And in the "-javabootclasspath" option the whole path must be
> specified, which is pretty long, and I don't know how to get its content
> from withing a script that runs the Scala program.
>
>
> I already tried to add "Xbootclasspath" option directly into the Scala
> starting script:
>
> "%_JAVACMD%" -Xbootclasspath/p:"" %_JAVA_OPTS% %_PROPS% -cp
> "%_TOOL_CLASSPATH%" scala.tools.nsc.MainGenericRunner %*
>
> (scala.bat / Scala 2.9.1 / Windows XP)
>
> But in this case the Java replacement classes get ignored.
>
>
> Perhaps someone has a solution?
>
> --
> EL