This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Prepend a directory to Java bootclasspath

4 replies
E. Labun
Joined: 2010-06-20,
User offline. Last seen 42 years 45 weeks ago.

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

Alec Zorab
Joined: 2010-05-18,
User offline. Last seen 42 years 45 weeks ago.
Re: Prepend a directory to Java bootclasspath

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

E. Labun
Joined: 2010-06-20,
User offline. Last seen 42 years 45 weeks ago.
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

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
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:?

E. Labun
Joined: 2010-06-20,
User offline. Last seen 42 years 45 weeks ago.
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).

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland