20

So I've been trying to work with the signal-collect framework and I downloaded the .jar files and extracted it into a folder. Currently the folder structure looks like:

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  

Where PageRank.scala is the Scala test code they provide, which is:

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
  }

}

I am a newbie when it comes to the JVM/Java/Scala, and this was my attempt at adding the .jar's to the classpath for compiling 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

I cannot figure out what is going wrong... what's happening? Thanks! Regards, -kstruct

Marco Bolis
  • 1,101
  • 2
  • 15
  • 29
adelbertc
  • 6,965
  • 10
  • 42
  • 65

3 Answers3

31

You need to pass both classpath paths as a single argument.

Try this:

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

It worked for me.

dhg
  • 50,861
  • 7
  • 115
  • 141
  • 4
    you can also use `;` to separate the jar names – Jus12 Apr 10 '12 at 06:48
  • 2
    +1 For completenss sake note that one has to **add the classpath both when compiling and when executing**. This is something I missed at a first glance. – JoErNanO Nov 18 '15 at 12:50
3

It seems that depending on an installed version of Java, wildcards in classpath to include multiple JARs might or might not work. I found this trick elsewhere on StackOverflow (note that you can have as many folders after the 'echo' as you wish, separated by spaces):

scalac -classpath $(echo *.jar dependencies/*.jar | tr ' ' ':')  PageRank.scala
scala -classpath $(echo *.jar dependencies/*.jar | tr ' ' ':')  PageRank
Maksym
  • 1,080
  • 1
  • 7
  • 13
1

for simplicity ,you can just use: scala -classpath $(echo *.jar dependencies/*.jar | tr ' ' ':') PageRank.scala