Frage

Der Befehl ': javap' in der Scala 2.9.1-Konsole benötigt die Tools.jar (von JDK6) im 'Klassenpfad'.Von der cmd-Zeile aus könnte dies mit dem Argument '-cp' oder der KLASSENPFAD-Umgebungsvariablen erfolgen.

Wie mache ich dasselbe für die Scala-Konsole, die von SBT mit den Befehlen 'console' und 'console-quick' aufgerufen wurde?

War es hilfreich?

Lösung

Lange Antwort, das könnte dir woanders helfen.

Wenn ich etwas über SBT wissen will, ich inspect es:

> 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, es gibt eine interessante Abhängigkeit in compile:full-classpath.Ich wünschte, es wäre so compile:full-classpath(for console), ist es aber nicht.In diesem Fall sollte es mir jedoch keine Probleme bereiten.Geschweige inspect es.

> 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, ich könnte weiter auf die Abhängigkeiten eingehen, aber ich denke nicht, dass es notwendig ist.Mal sehen, was drin ist:

> 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

Ok, da ist nichts Unerwartetes.Fügen wir hinzu tools.jar.

Um etwas zu ändern, muss ich verwenden set, und ich muss eine Menge Kamelkoffer und andere Regeln respektieren, damit es funktioniert.Wenn ich hätte compile:full-classpath(for console), das würde werden fullClasspath in Compile in console.Beachten Sie die Großbuchstaben in Compile, und das full-classpath werden fullClasspath, und die allgemeine Neuordnung von Elementnamen. Details hier.

Ich denke, man sollte in der Lage sein, die Ausgabe von zu nehmen show (oder zumindest, inspect) und füttere es gleich wieder an set, aber das ist nicht der Fall (vorerst jedenfalls), also lerne einfach diese Konvertierungsregeln.

Ich möchte nicht alles neu eingeben, sondern nur eine JAR-Datei hinzufügen.Ich muss verwenden += dafür.Die Operatoren, die zum Ändern von Dingen verwendet wurden, können gefunden werden hier.

Der Klassenpfad scheint etwas zu brauchen Attributed Zeug.Überprüfen Sie die detaillierten Dokumente auf Klassenpfad im SBT-Wiki, und finde heraus, wie man einen findet.Glücklicherweise sind die meisten Werte, die ich ändern möchte, nicht so schwer zu schaffen wie dieser.

> 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/)

Scheint funktioniert zu haben.Geschweige show sein Inhalt zu bestätigen, da sogar schreiben compile statt Compile könnte es dazu bringen, das Falsche zu ändern.

> 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

Ja, da ist es.Lass es uns testen:

> 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);
}

Erfolg!!!

Natürlich ist diese Sitzung eine Lüge.Es hat viel länger gedauert, bis ich dort angekommen bin, aber das ist meistens Übung.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top