无法在命令行上编译Scala项目

时间:2018-03-14 20:52:37

标签: scala

我有一个包含多个Scala文件的Scala项目以及一个带有一些预编译JAR依赖项的lib目录。我的项目目录结构如下所示:

project/src/main/scala/com/example/app/main.scala
project/src/main/scala/com/example/app/class1.scala
project/src/main/scala/com/example/app/class2.scala
project/lib/dependency1.jar
project/lib/dependency2.jar

其中main.scala是一个Scala对象,其主方法调用class1.scalaclass2.scala中的类。我的实际文件结构比这个简单的例子有更多的类和库。我想将编译后的类输出到文件夹root/compiled_classes

我尝试在命令行上编译,如此

> scalac -classpath "lib/*" -d compiled_classes src/main/scala/com/example/app/*

我收到错误,表明我的库依赖关系没有被正确理解......比如

src\main\scala\com\example\app\class1.scala:32: error: not found: type Model
    var model: Model = new LinkedHashModel()

其中Model是从其中一个依赖项文件导入的类。总而言之,我得到了476个错误,似乎每次我调用从依赖项导入的类。

如果它有所不同,这些.jar文件由SBT下载并最初存储在我的home/.ivy2文件夹中,我将其复制到project/lib文件夹中。也许这不是管理JAR的最佳方式,但我认为它应该有用。

如果有更好的方法通过命令行编译整个Scala项目,我也会接受其他建议。

编辑

以详细模式进行编译。这是输出的开头和结尾

C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar is not yet in the classpath cache
C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar is not yet in the classpath cache
C:\PROGRA~2\scala\bin\..\lib\jline-2.14.1.jar is not yet in the classpath cache
C:\PROGRA~2\scala\bin\..\lib\scala-compiler.jar is not yet in the classpath cache
C:\PROGRA~2\scala\bin\..\lib\scala-library.jar is not yet in the classpath cache
C:\PROGRA~2\scala\bin\..\lib\scala-parser-combinators_2.12-1.0.4.jar is not yet in the classpath cache
C:\PROGRA~2\scala\bin\..\lib\scala-reflect.jar is not yet in the classpath cache
C:\PROGRA~2\scala\bin\..\lib\scala-swing_2.12-2.0.0-M2.jar is not yet in the classpath cache
C:\PROGRA~2\scala\bin\..\lib\scala-xml_2.12-1.0.6.jar is not yet in the classpath cache
C:\PROGRA~2\scala\bin\..\lib\scalap-2.12.1.jar is not yet in the classpath cache
[search path for source files: ]
[search path for class files: C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar;C:\PROGRA~2\scala\bin\..\lib\jline-2.14.1.jar;C:\PROGRA~2\scala\bin\..\lib\scala-compiler.jar;C:\PROGRA~2\scala\bin\..\lib\scala-library.jar;C:\PROGRA~2\scala\bin\..\lib\scala-parser-combinators_2.12-1.0.4.jar;C:\PROGRA~2\scala\bin\..\lib\scala-reflect.jar;C:\PROGRA~2\scala\bin\..\lib\scala-swing_2.12-2.0.0-M2.jar;C:\PROGRA~2\scala\bin\..\lib\scala-xml_2.12-1.0.6.jar;C:\PROGRA~2\scala\bin\..\lib\scalap-2.12.1.jar]
[loaded package loader <root package> in 180ms]
[loaded package loader java in 2ms]
[loaded package loader java.lang in 25ms]
[loaded package loader scala.annotation in 2ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/reflect/package.class) in 39ms]
[loaded package loader scala.reflect in 47ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/package.class) in 60ms]
[loaded package loader scala in 89ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/CloneNotSupportedException.class) in 3ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/InterruptedException.class) in 1ms]
[loaded package loader java.io in 5ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/Throwable.class) in 18ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/Object.class) in 256ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/runtime/package.class) in 2ms]
[loaded package loader scala.runtime in 9ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/collection/package.class) in 3ms]
[loaded package loader scala.collection in 10ms]
[loaded package loader java.util in 11ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/UnsupportedEncodingException.class) in 1ms]
[loaded package loader java.nio in 3ms]
[loaded package loader java.nio.charset in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/String.class) in 36ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/Comparable.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/Serializable.class) in 1ms]
[promote the dependency of lambdalift: erasure => posterasure]

...

src\main\scala\com\example\app\class1.scala:325: error: not found: type RepositoryConnection
    def retrieveBMIData (cxn: RepositoryConnection): ArrayBuffer[ArrayBuffer[Value]] =
                              ^
src\main\scala\com\example\app\class1.scala:32: error: not found: type Model
        var model: Model = new LinkedHashModel()
                   ^
src\main\scala\com\example\app\class1.scala:32: error: not found: type LinkedHashModel
        var model: Model = new LinkedHashModel()
                               ^
src\main\scala\com\example\app\class1.scala:298: error: not found: type Value
    def handleMultipleBMIRecordingsForSingleEncounter(result: ArrayBuffer[ArrayBuffer[Value]], a: Int, f: ValueFactory): Array[Object] =
                                                                                      ^
src\main\scala\com\example\app\class1.scala:298: error: not found: type ValueFactory
    def handleMultipleBMIRecordingsForSingleEncounter(result: ArrayBuffer[ArrayBuffer[Value]], a: Int, f: ValueFactory): Array[Object] =
                                                                                                          ^
src\main\scala\com\example\app\class1.scala:189: error: not found: type Model
    def addBMIInconclusion(model: Model, encounter: Value, explanation: String, f: ValueFactory): Model =
                                                                                                  ^
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/IllegalArgumentException.class) in 1ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/collection/generic/MutableMapFactory.class) in 2ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/collection/generic/MapFactory.class) in 1ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/collection/generic/GenMapFactory.class) in 5ms]
[loaded package loader java.nio.channels in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/IOException.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/System.class) in 8ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/unchecked.class) in 1ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/noinline.class) in 1ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/inline.class) in 0ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/collection/immutable/NumericRange.class) in 2ms]
[loaded module class loader in 5ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/collection/immutable/Range.class) in 3ms]
[loaded module class loader in 4ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/reflect/macros/internal/macroImpl.class) in 4ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/collection/parallel/immutable/ParRange.class) in 4ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/annotation/unchecked/uncheckedVariance.class) in 2ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/annotation/TypeConstraint.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/FileNotFoundException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/FileInputStream.class) in 3ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/InputStream.class) in 3ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/Closeable.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/AutoCloseable.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/SyncFailedException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/FileDescriptor.class) in 4ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/net/MalformedURLException.class) in 1ms]
[loaded package loader java.nio.file in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/File.class) in 9ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/InvalidPropertiesFormatException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/Properties.class) in 8ms]
[loaded package loader java.util.function in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/Map.class) in 7ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/Hashtable.class) in 17ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/Dictionary.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/Reader.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/Readable.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/NullPointerException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/net/URISyntaxException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/net/URI.class) in 6ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/PrintWriter.class) in 9ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/Writer.class) in 3ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/Appendable.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/Flushable.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/OutputStream.class) in 2ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/Function3.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/UUID.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/nio/file/WatchEvent.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/nio/file/Path.class) in 11ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/nio/file/Paths.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/BufferedReader.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/FileReader.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/InputStreamReader.class) in 5ms]
[loaded package loader sun.util in 1ms]
[loaded package loader sun.util.locale in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/MissingResourceException.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/Locale.class) in 25ms]
[loaded package loader java.text in 1ms]
[loaded package loader java.time in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/Calendar.class) in 6ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/TimeZone.class) in 3ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/text/SimpleDateFormat.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/text/ParseException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/text/DateFormat.class) in 4ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/text/AttributedCharacterIterator.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/text/Format.class) in 8ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/text/DateFormatSymbols.class) in 5ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/util/Date.class) in 5ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/lang/StringBuffer.class) in 6ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/text/FieldPosition.class) in 3ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/FileWriter.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/OutputStreamWriter.class) in 5ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/net/URL.class) in 3ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/net/URLStreamHandler.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/net/ConnectException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/net/SocketException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/nio/charset/CharacterCodingException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/nio/charset/CharsetDecoder.class) in 4ms]
[loaded package loader java.nio.charset.spi in 0ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/nio/charset/Charset.class) in 5ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/BufferedInputStream.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/io/FilterInputStream.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/security/NoSuchAlgorithmException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/security/NoSuchProviderException.class) in 2ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/security/DigestException.class) in 1ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/security/MessageDigest.class) in 22ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/security/Provider.class) in 5ms]
[loaded class file C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar(java/security/MessageDigestSpi.class) in 1ms]
[loaded class file C:\PROGRA~2\scala\bin\..\lib\scala-library.jar(scala/Function2.class) in 2ms]
[typer in 6508ms]
[total in 7299ms]
476 errors found

0 个答案:

没有答案