:Scalaの2.9.1コンソールの「てjavap」コマンドは、「クラスパス」に(JDK6から)のtools.jarを必要としています。 cmd-lineから、 '-cp'引数またはCLASSPATH環境変数を使って行えます。 「コンソール」と「コンソール・迅速」コマンドでSBTから呼び出されたScalaのコンソールのために同じことを行うにはどのようには、SBTのプロジェクトのクラスパスにtools.jarを追加
?
:Scalaの2.9.1コンソールの「てjavap」コマンドは、「クラスパス」に(JDK6から)のtools.jarを必要としています。 cmd-lineから、 '-cp'引数またはCLASSPATH環境変数を使って行えます。 「コンソール」と「コンソール・迅速」コマンドでSBTから呼び出されたScalaのコンソールのために同じことを行うにはどのようには、SBTのプロジェクトのクラスパスにtools.jarを追加
?
長い回答は、他の場所で役立つかもしれません。
私はSBTで何かを知りたい場合は、私はそれをinspect
:
> inspect console
[info] Task: Unit
[info] Description:
[info] Starts the Scala interpreter with the project classes on the classpath.
[info] Provided by:
[info] {file:/home/dcs/github/anti-xml/}default-39679a/compile:console
[info] Dependencies:
[info] compile:compilers(for console)
[info] compile:full-classpath
[info] compile:scalac-options(for console)
[info] compile:initial-commands(for console)
[info] compile:streams(for console)
[info] Delegates:
[info] compile:console
[info] *:console
[info] {.}/compile:console
[info] {.}/*:console
[info] */compile:console
[info] */*:console
[info] Related:
[info] test:console
[OK]を、compile:full-classpath
で興味深いの依存関係があります。私はそれがcompile:full-classpath(for console)
だったらいいのに、そうではありません。しかし、この場合でも私は問題を起こすべきではありません。それをinspect
としよう。
> inspect compile:full-classpath
[info] Task: scala.collection.Seq[sbt.Attributed[java.io.File]]
[info] Description:
[info] The exported classpath, consisting of build products and unmanaged and managed, internal and external dependencies.
[info] Provided by:
[info] {file:/home/dcs/github/anti-xml/}default-39679a/compile:full-classpath
[info] Dependencies:
[info] compile:exported-products
[info] compile:dependency-classpath
[info] Reverse dependencies:
[info] compile:console
[info] Delegates:
[info] compile:full-classpath
[info] *:full-classpath
[info] {.}/compile:full-classpath
[info] {.}/*:full-classpath
[info] */compile:full-classpath
[info] */*:full-classpath
[info] Related:
[info] compile:full-classpath(for doc)
[info] test:full-classpath
[info] test:full-classpath(for doc)
[info] *:full-classpath(for console)
[info] runtime:full-classpath
[info] compile:full-classpath(for console)
[OK]を、私は依存関係にさらに行くことができますが、私はそれが必要だとは思いません。内部に何が入っているかを見てみましょう:
> show compile:full-classpath
[warn] Credentials file /home/dcs/.ivy2/.credentials does not exist
[info] List(Attributed(/home/dcs/github/anti-xml/target/scala-2.9.1/classes), Attributed(/home/dcs/.sbt/boot/scala-2.9.1/lib/scala-library.jar))
[success] Total time: 0 s, completed Dec 7, 2011 3:49:30 PM
tools.jar
を追加しましょう。
set
を使用する必要が何かを変更するには、と私はキャメルケースと、それが働いて得るために他のルールの束を尊重しなければなりません。
compile:full-classpath(for console)
があれば、それは
fullClasspath in Compile in console
になります。
Compile
に大文字があり、
full-classpath
が
fullClasspath
になり、要素名の一般的な並べ替えが行われたことに注意してください。
Details here。
ので、ちょうどこれらの変換ルールを学び、(今のところ、とにかく)私は1つは、(少なくともまたは、inspect
)show
の出力を取り、右バックset
にそれを供給することができるはずだと思うが、それはケースではありません。
私はちょうど1つのJARファイルを追加し、すべてを再入力する必要はありません。私は+=
を使用する必要があります。物を変更するために使用された演算子はhereです。
クラスパスには、いくつかのAttributed
のものを必要とするようです。 SBT wikiのClasspathの詳細な文書を確認し、それを思いつく方法を理解してください。幸いにも、私が変えたいと考えるかもしれないほとんどの値は、このように作成するのが難しくありません。
> set fullClasspath in Compile += Attributed.blank(file("/usr/lib/jvm/java-6-sun-1.6.0.26/lib/tools.jar"))
[info] Reapplying settings...
[info] Set current project to anti-xml (in build file:/home/dcs/github/anti-xml/)
と思われます。の代わりにcompile
と書いても、間違ったことを変更する可能性があるので、show
の内容を確認しましょう。
> show compile:full-classpath
[warn] Credentials file /home/dcs/.ivy2/.credentials does not exist
[info] List(Attributed(/home/dcs/github/anti-xml/target/scala-2.9.1/classes), Attributed(/home/dcs/.sbt/boot/scala-2.9.1/lib/scala-library.jar), Attributed(/usr/lib/jvm/java-6-sun-1.6.0.26/lib/tools.jar))
[success] Total time: 0 s, completed Dec 7, 2011 3:50:07 PM
これはあります。テストしましょう:
> console
[warn] Credentials file /home/dcs/.ivy2/.credentials does not exist
[info] Starting scala interpreter...
[info]
import com.codecommit.antixml._
bookstore: com.codecommit.antixml.Elem = <bookstore><book><title>For Whom the Bell Tolls</title><author>Hemmingway</author></book><book><title>I, Robot</title><author>Isaac Asimov</author></book><book><title>Programming Scala</title><author>Dean Wampler</author><author>Alex Payne</author></book></bookstore>
books: com.codecommit.antixml.Zipper[com.codecommit.antixml.Elem] = <book><title>For Whom the Bell Tolls</title><author>Hemmingway</author></book><book><title>I, Robot</title><author>Isaac Asimov</author></book><book><title>Programming Scala</title><author>Dean Wampler</author><author>Alex Payne</author></book>
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :javap com.codecommit.antixml.Elem
Compiled from "node.scala"
public class com.codecommit.antixml.Elem extends java.lang.Object implements com.codecommit.antixml.Node,com.codecommit.antixml.Selectable,scala.ScalaObject,scala.Product,scala.Serializable{
public static final scala.Function1 tupled();
public static final scala.Function1 curry();
public static final scala.Function1 curried();
public static final boolean isValidName(java.lang.String);
public scala.collection.Iterator productIterator();
public scala.collection.Iterator productElements();
public java.lang.Object $bslash(com.codecommit.antixml.Selector, com.codecommit.antixml.CanBuildFromWithZipper);
public java.lang.Object $bslash$bslash(com.codecommit.antixml.Selector, com.codecommit.antixml.CanBuildFromWithZipper);
public java.lang.Object $bslash$bslash$bang(com.codecommit.antixml.Selector, com.codecommit.antixml.CanBuildFromWithZipper);
public java.lang.Object select(com.codecommit.antixml.Selector, com.codecommit.antixml.CanBuildFromWithZipper);
public com.codecommit.antixml.Zipper toZipper();
public scala.Option prefix();
public java.lang.String name();
public com.codecommit.antixml.Attributes attrs();
public scala.collection.immutable.Map scope();
public com.codecommit.antixml.Group children();
public com.codecommit.antixml.Elem canonicalize();
public java.lang.String toString();
public com.codecommit.antixml.Group toGroup();
public com.codecommit.antixml.Group copy$default$5();
public scala.collection.immutable.Map copy$default$4();
public com.codecommit.antixml.Attributes copy$default$3();
public java.lang.String copy$default$2();
public scala.Option copy$default$1();
public com.codecommit.antixml.Elem copy(scala.Option, java.lang.String, com.codecommit.antixml.Attributes, scala.collection.immutable.Map, com.codecommit.antixml.Group);
public int hashCode();
public boolean equals(java.lang.Object);
public java.lang.String productPrefix();
public int productArity();
public java.lang.Object productElement(int);
public boolean canEqual(java.lang.Object);
public com.codecommit.antixml.Elem(scala.Option, java.lang.String, com.codecommit.antixml.Attributes, scala.collection.immutable.Map, com.codecommit.antixml.Group);
}
成功!!!もちろん
、このセッションは嘘です。私がそこに到着するまでにはずっと時間がかかりましたが、それは主に練習です。
https://github.com/ensime/ensime-server/blob/master/build.sbt#L35
// epic hack to get the tools.jar JDK dependency
val JavaTools = List[Option[String]] (
// manual
sys.env.get("JDK_HOME"),
sys.env.get("JAVA_HOME"),
// osx
try Some("/usr/libexec/java_home".!!.trim)
catch {
case _: Throwable => None
},
// fallback
sys.props.get("java.home").map(new File(_).getParent),
sys.props.get("java.home")
).flatten.map { n =>
new File(n + "/lib/tools.jar")
}.find(_.exists).getOrElse (
throw new FileNotFoundException (
"""Could not automatically find the JDK/lib/tools.jar.
|You must explicitly set JDK_HOME or JAVA_HOME.""".stripMargin
)
)
詳細な回答のために、ダニエル、ありがとうございました。 SBT 0.12.0で –
は私が手: $ SBTコンソール ScalaはコンパイルにfullClasspathを設定> + = Attributed.blank(ファイル( "は/ usr/libに/ JVM/jdk1.7.0/libに/ tools.jarの")) :1:エラー: ';'期待されていたが。見つかりました。 コンパイル時にfullClasspathを設定する+ Attributed.blank(ファイル( "/ usr/lib/jvm/jdk1.7.0/lib/tools.jar")) –
これはどのSBTバージョンで起こったのか不明ですが、コンソール:: fullClasspath'あなたが望むように。 'fullClasspath in compile in console'が動作します。 –