14
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ScalaでHelloWorldしようとして、いいパンチもらった話(object java.lang.Object in compiler mirror not found.)

Last updated at Posted at 2018-04-19

TL;DR

Scala の平均給与めっちゃ高かったんで になんとなく興味湧いたのでやってみようかと思い、空いてる時間でとりあえず Hello Worldするためにプロジェクトを作ることにしました。

言語別平均年収ランキング

まあ、いろいろなとこでインストール系はやってるので、今更良いでしょう。

フレームワークも一番人気のやつを使っておけば問題ないはず。

playframework

さて、さっそく。

console
$ activator new my-first-app play-scala

特に問題なく完了(WARNING出てた気がしますが...)

console
$ cd my-first-app/
$ activator
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by activator.ActivatorProxyAuthenticator$ (file:/Users/(username)/.sbt/boot/scala-2.11.8/com.typesafe.activator/activator-launcher/1.3.12/activator-launcher-1.3.12.jar) to field java.net.Authenticator.theAuthenticator
WARNING: Please consider reporting this to the maintainers of activator.ActivatorProxyAuthenticator$
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
error: error while loading package, Missing dependency 'object java.lang.Object in compiler mirror', required by /Users/(username)/.sbt/boot/scala-2.10.6/lib/scala-library.jar(scala/package.class)
error: error while loading package, Missing dependency 'object java.lang.Object in compiler mirror', required by /Users/(username)/.sbt/boot/scala-2.10.6/lib/scala-library.jar(scala/runtime/package.class)
scala.reflect.internal.MissingRequirementError: object java.lang.Object in compiler mirror not found.
	at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:16)
	at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:17)
	at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:48)
	at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:40)
	at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:40)
	at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:61)
	at scala.reflect.internal.Mirrors$RootsBase.getClassByName(Mirrors.scala:99)
	at scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(Mirrors.scala:102)
	at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:264)
	at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:264)
	at scala.reflect.internal.Definitions$DefinitionsClass.AnyRefClass$lzycompute(Definitions.scala:263)
	at scala.reflect.internal.Definitions$DefinitionsClass.AnyRefClass(Definitions.scala:263)
	at scala.reflect.internal.Definitions$DefinitionsClass.specialPolyClass(Definitions.scala:1120)
	at scala.reflect.internal.Definitions$DefinitionsClass.RepeatedParamClass$lzycompute(Definitions.scala:407)
	at scala.reflect.internal.Definitions$DefinitionsClass.RepeatedParamClass(Definitions.scala:407)
	at scala.reflect.internal.Definitions$DefinitionsClass.syntheticCoreClasses$lzycompute(Definitions.scala:1154)
	at scala.reflect.internal.Definitions$DefinitionsClass.syntheticCoreClasses(Definitions.scala:1152)
	at scala.reflect.internal.Definitions$DefinitionsClass.symbolsNotPresentInBytecode$lzycompute(Definitions.scala:1196)
	at scala.reflect.internal.Definitions$DefinitionsClass.symbolsNotPresentInBytecode(Definitions.scala:1196)
	at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1261)
	at scala.tools.nsc.Global$Run.<init>(Global.scala:1290)
	at sbt.compiler.Eval$$anon$1.<init>(Eval.scala:141)
	at sbt.compiler.Eval.run$lzycompute$1(Eval.scala:141)
	at sbt.compiler.Eval.run$1(Eval.scala:141)
	at sbt.compiler.Eval.unlinkAll$1(Eval.scala:144)
	at sbt.compiler.Eval.evalCommon(Eval.scala:153)
	at sbt.compiler.Eval.eval(Eval.scala:96)
	at sbt.EvaluateConfigurations$.evaluateDslEntry(EvaluateConfigurations.scala:177)
	at sbt.EvaluateConfigurations$$anonfun$9.apply(EvaluateConfigurations.scala:117)
	at sbt.EvaluateConfigurations$$anonfun$9.apply(EvaluateConfigurations.scala:115)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.immutable.List.foreach(List.scala:318)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
	at scala.collection.AbstractTraversable.map(Traversable.scala:105)
	at sbt.EvaluateConfigurations$.evaluateSbtFile(EvaluateConfigurations.scala:115)
	at sbt.Load$.sbt$Load$$loadSettingsFile$1(Load.scala:725)
	at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:731)
	at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:730)
	at scala.collection.MapLike$class.getOrElse(MapLike.scala:128)
	at scala.collection.AbstractMap.getOrElse(Map.scala:58)
	at sbt.Load$.sbt$Load$$memoLoadSettingsFile$1(Load.scala:730)
	at sbt.Load$$anonfun$loadFiles$1$2.apply(Load.scala:738)
	at sbt.Load$$anonfun$loadFiles$1$2.apply(Load.scala:738)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
	at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
	at scala.collection.AbstractTraversable.map(Traversable.scala:105)
	at sbt.Load$.loadFiles$1(Load.scala:738)
	at sbt.Load$.discoverProjects(Load.scala:749)
	at sbt.Load$.discover$1(Load.scala:555)
	at sbt.Load$.loadTransitive(Load.scala:584)
	at sbt.Load$.loadProjects$1(Load.scala:452)
	at sbt.Load$.loadUnit(Load.scala:456)
	at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:291)
	at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:291)
	at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:91)
	at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:90)
	at sbt.BuildLoader.apply(BuildLoader.scala:140)
	at sbt.Load$.loadAll(Load.scala:344)
	at sbt.Load$.loadURI(Load.scala:299)
	at sbt.Load$.load(Load.scala:295)
	at sbt.Load$.load(Load.scala:286)
	at sbt.Load$.apply(Load.scala:140)
	at sbt.Load$.buildPluginDefinition(Load.scala:836)
	at sbt.Load$.buildPlugins(Load.scala:802)
	at sbt.Load$.plugins(Load.scala:790)
	at sbt.Load$.loadUnit(Load.scala:441)
	at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:291)
	at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:291)
	at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:91)
	at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:90)
	at sbt.BuildLoader.apply(BuildLoader.scala:140)
	at sbt.Load$.loadAll(Load.scala:344)
	at sbt.Load$.loadURI(Load.scala:299)
	at sbt.Load$.load(Load.scala:295)
	at sbt.Load$.load(Load.scala:286)
	at sbt.Load$.apply(Load.scala:140)
	at sbt.Load$.defaultLoad(Load.scala:36)
	at sbt.BuiltinCommands$.liftedTree1$1(Main.scala:492)
	at sbt.BuiltinCommands$.doLoadProject(Main.scala:492)
	at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:484)
	at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:484)
	at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
	at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
	at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
	at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
	at sbt.Command$.process(Command.scala:93)
	at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
	at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
	at sbt.State$$anon$1.process(State.scala:184)
	at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
	at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
	at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
	at sbt.MainLoop$.next(MainLoop.scala:96)
	at sbt.MainLoop$.run(MainLoop.scala:89)
	at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:68)
	at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:63)
	at sbt.Using.apply(Using.scala:24)
	at sbt.MainLoop$.runWithNewLog(MainLoop.scala:63)
	at sbt.MainLoop$.runAndClearLast(MainLoop.scala:46)
	at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:30)
	at sbt.MainLoop$.runLogged(MainLoop.scala:22)
	at sbt.StandardMain$.runManaged(Main.scala:54)
	at sbt.xMain.run(Main.scala:29)
	at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
	at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
	at xsbt.boot.Launch$.run(Launch.scala:109)
	at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
	at xsbt.boot.Launch$.launch(Launch.scala:117)
	at xsbt.boot.Launch$.apply(Launch.scala:18)
	at xsbt.boot.Boot$.runImpl(Boot.scala:41)
	at xsbt.boot.Boot$.main(Boot.scala:17)
	at xsbt.boot.Boot.main(Boot.scala)
[error] scala.reflect.internal.MissingRequirementError: object java.lang.Object in compiler mirror not found.
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q

こんなん出るなんて、書いてなかったんだけど?

どうもインストール済みのjava(java10)が問題なのかダメみたいですね()
エラーでググると、java.lang.Objectの部分がscalaになった記事ばかりが上の方にきていたので、見つけにくかったです。(Failed to initialize compiler: object java.lang.Object in compiler mirror not found
)
というわけで、java8なら問題ないはずなので、インストール。

console
$ brew cask install caskroom/versions/java8

java8入った!
ので、早速切り替える。

console
$ vi ~/.bashrc
.bashrc
export JAVA_HOME=`/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java_home -v “1.8”`
PATH=$JAVA_HOME/bin:$PATH
console
$ source ~/.bashrc

$ activator run
...
...
(Server started, use Ctrl+D to stop and go back to the console...)
スクリーンショット 2018-04-19 15.08.43.png

やったね。
すごい目的達成感あったけど(さらっと原因ぽいもの流してますけど、2時間くらい悩んでたので)、helloworldを書きに来たので、せっかくなので書く。

routes
GET			/hello									controllers.GreetController.index
GreetController.scala
package controllers

import javax.inject._
import play.api._
import play.api.mvc._

@Singleton
class GreetController @Inject() extends Controller {

  def index = Action {
    Ok("Hello world")
  }
}

localhost:9000/helloにアクセス。

スクリーンショット 2018-04-19 14.57.48.png

ちっさwww

環境

・Mac OS X EI Caption 10.11.6
・Play 2.5.10

console
$ scala -version
Scala code runner version 2.12.5 -- Copyright 2002-2018, LAMP/EPFL and Lightbend, Inc.

$ java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

参考

playframework Actions, Controllers and Results

追記[2018/09/12]

エラー内容で引っかからないと使えないので、タイトル追加しました。

14
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?