添加的.jar的类路径(斯卡拉)(Adding .jar's to classpath (S

2019-07-28 21:27发布

所以,我一直在试图与工作信号收集框架,我下载了.jar文件,并提取它到一个文件夹。 目前,该文件夹结构是这样的:

LICENSE.txt  
PageRank.scala  
core-1.1.1-sources.jar  
dependencies/  
javaapi-1.1.1-sources.jar  
NOTICE.txt  
README.txt  
core-1.1.1.jar  
javaapi-1.1.1-javadoc.jar  
javaapi-1.1.1.jar  

其中PageRank.scala是他们所提供的斯卡拉测试代码,这就是:

import com.signalcollect._

object PageRank extends App {
  val graph = GraphBuilder.build
  graph.addVertex(new PageRankVertex(id=1))
  graph.addVertex(new PageRankVertex(id=2))
  graph.addEdge(new PageRankEdge(sourceId=1, targetId=2))
  graph.addEdge(new PageRankEdge(sourceId=2, targetId=1))
  graph.execute
  graph.foreachVertex(println(_))
  graph.shutdown
}

class PageRankVertex(id: Any, dampingFactor: Double=0.85)
    extends DataGraphVertex(id=id, state=1-dampingFactor) {
  type Signal = Double

  def collect(oldState: Double, mostRecentSignals: Iterable[Double]): Double = {
    1 - dampingFactor + dampingFactor * mostRecentSignals.sum
  }

}

class PageRankEdge(sourceId: Any, targetId: Any)
    extends DefaultEdge(sourceId, targetId) {
  type SourceVertex = PageRankVertex

  def signal(sourceVertex: PageRankVertex) = {
    sourceVertex.state * weight / sourceVertex.sumOfOutWeights
  }

}

我是一个新手,当涉及到JVM /的Java / Scala中,这是我在加入尝试.jar's类路径编译PageRank.scala

$ scalac -classpath *.jar dependencies/*.jar PageRank.scala 
error: IO error while decoding core-1.1.1.jar with UTF-8
Please try specifying another one using the -encoding option
error: IO error while decoding javaapi-1.1.1-javadoc.jar with UTF-8
Please try specifying another one using the -encoding option
error: IO error while decoding javaapi-1.1.1-sources.jar with UTF-8
Please try specifying another one using the -encoding option
error: IO error while decoding javaapi-1.1.1.jar with UTF-8
Please try specifying another one using the -encoding option
error: IO error while decoding dependencies/je-3.2.76.jar with UTF-8
Please try specifying another one using the -encoding option
error: IO error while decoding dependencies/scala-library-2.9.1.jar with UTF-8
Please try specifying another one using the -encoding option
6 errors found

我想不出什么错误?发生了什么事? 谢谢! 问候,-kstruct

Answer 1:

你需要两个类路径的路径传递作为一个参数。

试试这个:

$ scalac -classpath "*.jar:dependencies/*.jar" PageRank.scala
$ scala -classpath "*.jar:dependencies/*.jar" PageRank
PageRankVertex(id=2, state=0.9999999999999997)
PageRankVertex(id=1, state=0.9999999999999997)

它为我工作。



Answer 2:

看来,这取决于一个Java安装的版本,在类路径通配符包括多个JAR可能会或可能无法正常工作。 我发现这招在其他地方在计算器上(注意,你可以有后的“回响”多个文件夹如你所愿,用空格隔开):

scalac -classpath $(echo *.jar dependencies/*.jar | tr ' ' ':')  PageRank.scala
scala -classpath $(echo *.jar dependencies/*.jar | tr ' ' ':')  PageRank


Answer 3:

为简单起见,你可以使用:斯卡拉-classpath $(回声的* .jar依赖性/ *罐子| TR ''。 ':')PageRank.scala



文章来源: Adding .jar's to classpath (Scala)