I tried setting the classpath explicitly in the settings. Classpath gets
printed properly, it has the scala jars in it like
scala-compiler-2.10.4.jar, scala-library-2.10.4.jar.
It did not help. Still runs great with IntelliJ, but runs into issues when
running from the command line.
val cl = this.getClass.getClassLoader
val urls = cl match {
case cl: java.net.URLClassLoader => cl.getURLs.toList
case a => sys.error("oops: I was expecting an URLClassLoader, found a
" + a.getClass)
}
val classpath = urls map {_.toString}
println("classpath=" + classpath);
settings.classpath.value =
classpath.distinct.mkString(java.io.File.pathSeparator)
settings.embeddedDefaults(cl)
-Jayant
On Mon, Jun 27, 2016 at 3:19 PM, Jayant Shekhar <[email protected]>
wrote:
> Hello,
>
> I'm trying to run scala code in a Web Application.
>
> It runs great when I am running it in IntelliJ
> Run into error when I run it from the command line.
>
> Command used to run
> ------------------------------
>
> java -Dscala.usejavacp=true -jar target/XYZ.war
> --spring.config.name=application,db,log4j
> --spring.config.location=file:./conf/history
>
> Error
> -------
>
> Failed to initialize compiler: object scala.runtime in compiler mirror not
> found.
>
> ** Note that as of 2.8 scala does not assume use of the java classpath.
>
> ** For the old behavior pass -usejavacp to scala, or if using a Settings
>
> ** object programatically, settings.usejavacp.value = true.
>
> 16/06/27 15:12:02 WARN SparkIMain: Warning: compiler accessed before init
> set up. Assuming no postInit code.
>
>
> I'm also setting the following:
> ----------------------------------------
>
> val settings = new Settings()
>
> settings.embeddedDefaults(Thread.currentThread().getContextClassLoader())
>
> settings.usejavacp.value = true
>
> Any pointers to the solution would be great.
>
> Thanks,
> Jayant
>
>