加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 在sbt项目的类路径中添加tools.jar

发布时间:2020-12-16 09:33:31 所属栏目:安全 来源:网络整理
导读:scala 2.9.1控制台中的’:javap’命令需要在’classpath’中的tools.jar(来自JDK6)。从cmd-line可以用-cp参数或CLASSPATH环境变量来完成。 如何使用“控制台”和“控制台快速”命令从SBT调用的scala控制台执行相同操作? 解决方法 长的答案,这可能会帮助你
scala 2.9.1控制台中的’:javap’命令需要在’classpath’中的tools.jar(来自JDK6)。从cmd-line可以用-cp参数或CLASSPATH环境变量来完成。

如何使用“控制台”和“控制台快速”命令从SBT调用的scala控制台执行相同操作?

解决方法

长的答案,这可能会帮助你在别处。

如果我想了解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

好的,在编译中有一个有趣的依赖:full-classpath。我希望它是编译:full-classpath(对于控制台),但它不是。不应该在这种情况下引起麻烦。我们来看看吧

> 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。

要改变我必须使用的东西,我必须尊重一堆骆驼案和其他规则才能使其工作。如果我有编译:full-classpath(对于控制台),那么在控制台的Compile中将成为fullClasspath。注意Compile中的大写字母,并且全类路径变为fullClasspath,并且元素名称的一般重新排序。 Details here。

我认为应该能够输出展示(或至少是检查),然后将其反馈给设置,但事实并非如此(直到现在),所以只需要学习这些转换规则。

我不想重新键入所有内容,只需添加一个JAR文件。我需要使用=。运算符用来改变事情可以在here找到。

类路径似乎需要一些Attributed的东西。在SBT维基中查看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/)

似乎已经工作了让我们展示其内容来确认,因为即使编写编译而不是编译可能会改变错误的东西。

> 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,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,com.codecommit.antixml.Group);
}

成功!!!

当然这个会话是谎言。我花了更长的时间到达那里,但这主要是练习。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读