سؤال

يحتاج الأمر ':javap' في وحدة التحكم scala 2.9.1 إلى الأدوات.jar (من JDK6) في 'classpath'.من سطر cmd يمكن القيام بذلك باستخدام الوسيطة "-cp" أو متغير البيئة CLASSPATH.

كيف تفعل الشيء نفسه بالنسبة لوحدة التحكم scala التي تم استدعاؤها من SBT باستخدام أوامر "console" و"console-quick"؟

هل كانت مفيدة؟

المحلول

إجابة طويلة، قد تساعدك في مكان آخر.

إذا أردت أن أعرف شيئًا ما في 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

حسنًا، هناك تبعية مثيرة للاهتمام في 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)

حسنًا، يمكنني المضي قدمًا في التبعيات، لكنني لا أعتقد أن ذلك ضروري.دعونا نرى ما بداخله:

> 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, ، وإعادة الترتيب العام لأسماء العناصر. التفاصيل هنا.

أعتقد أنه ينبغي للمرء أن يكون قادرًا على أخذ مخرجات show (أو على الأقل، inspect) وإطعامه مباشرة إلى set, ، ولكن هذا ليس هو الحال (في الوقت الحالي، على أي حال)، لذا تعلم فقط قواعد التحويلات هذه.

لا أريد إعادة كتابة كل شيء، فقط قم بإضافة ملف JAR واحد.أحتاج إلى استخدام += من أجل هذا.يمكن العثور على العوامل المستخدمة لتغيير الشيء هنا.

يبدو أن مسار الفصل يحتاج إلى بعض Attributed أشياء.تحقق من المستندات التفصيلية على مسار الفصل في ويكي SBT، واكتشف كيفية التوصل إلى واحدة.لحسن الحظ، فإن إنشاء معظم القيم التي قد أرغب في تغييرها ليس بالصعوبة التي تخلقها هذه القيمة.

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

يبدو أنها عملت.دعونا show محتواه للتأكيد، منذ حتى الكتابة compile بدلاً من Compile قد تحصل عليه لتغيير الشيء الخطأ.

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

نجاح!!!

بالطبع هذه الجلسة كذبة.لقد استغرق الأمر وقتًا أطول بكثير بالنسبة لي للوصول إلى هناك، ولكن هذا في الغالب تدريب.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top