Include jar file in Scala interpreter

后端 未结 7 1080
囚心锁ツ
囚心锁ツ 2020-12-28 14:54

Is it possible to include a jar file run running the Scala interpreter?

My code is working when I compile from scalac:

scalac script.scala -classpath         


        
相关标签:
7条回答
  • 2020-12-28 15:42

    "lib/*.jar" generates a list with blank between items not ":" or ";" as required. Since Java 6 "lib/*" should work, but sometimes doesn't (classpath is set somewhere else)

    I use a script like:

    1. Windows:

      @rem all *.jars in lib subdirectory
      
      @echo off
      
      set clp=.
      
      for %%c in (lib\*.jar) do call :Setclasspath %%c
      
      echo The classpath is %clp% 
      
      scala -classpath %clp% script.scala
      
      exit /B %ERRORLEVEL%
      
      :Setclasspath
      set clp=%clp%;%~1
      exit /B 0
      
    2. Linux:

      #!/bin/bash
      
      #all *.jars in lib subdirectory
      
      clp="."
      
      for file in lib/*
      do
        clp="$clp:$file"
      done
      
      echo $clp
      
      
      scala -classpath $clp script.scala
      
    0 讨论(0)
提交回复
热议问题