gpt4 book ai didi

scala - 使用 SBT 或 gradle 将 scala 编译为 assembly jar

转载 作者:行者123 更新时间:2023-12-04 23:42:45 25 4
gpt4 key购买 nike

昨天问过,这个没有重复。

我可以使用 sbt 或 gradle 来编译 helloworld,但是当涉及到其他一些对象时,我遇到了新问题。以下是我所做的任何人都可以告诉我如何解决它吗?

tong@tong-VirtualBox:/usr/local/jars$ sudo mkdir Log
tong@tong-VirtualBox:/usr/local/jars$ cd Log
tong@tong-VirtualBox:/usr/local/jars/Log$ mkdir -p src/main/scala
tong@tong-VirtualBox:/usr/local/jars/Log$ mkdir -p src/main/resources
tong@tong-VirtualBox:/usr/local/jars/Log$ mkdir -p src/test/scala
tong@tong-VirtualBox:/usr/local/jars/Log$ mkdir -p src/test/resources
tong@tong-VirtualBox:/usr/local/jars/Log$ cd src/main/scala
tong@tong-VirtualBox:/usr/local/jars/Log/src/main/scala$ mkdir -p com/tong/gradle
tong@tong-VirtualBox:/usr/local/jars/Log/src/main/scala$ vi com/tong/gradle/Log.scala


package org.apache.spark.h2o.utils

import water.fvec.{NewChunk, Frame, Chunk}
import water._

/** Transformation from double vector to log vector. */
class Log extends MRTask[Log] {
override def map(c: Chunk, nc: NewChunk): Unit = {
for (row <- 0 until c.len()) {
nc.addNum(Math.log(c.atd(row)))
}
}
}



tong@tong-VirtualBox:/usr/local/jars/Log/src/main/scala$ cd ../../..
tong@tong-VirtualBox:/usr/local/jars/Log$ vi build.gradle

apply plugin: 'scala'

jar {
baseName = 'tong'
version = '1.0'
manifest {
attributes 'Main-Class': 'com.tong.gradle.Log' }

}
dependencies {
compile 'org.scala-lang:scala-library:2.10.4'
}

tong@tong-VirtualBox:/usr/local/jars/Log$ gradle build
:compileJava UP-TO-DATE
:compileScala

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Could not find org.scala-lang:scala-library:2.10.4.
Required by:
:Log:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 6.917 secs

或者如果你能告诉我如何在 SBT 中完成它也很好,谢谢!

最佳答案

sbt 版本。

$ mkdir project
$ vi project/build.properties

sbt.version=0.13.9

$ vi project/plugins.sbt

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.0")

$ vi build.sbt

name := "tong"
version := "1.0"
scalaVersion := "2.10.6"
mainClass in assembly := Some("com.tong.gradle.Log")

$ sbt assembly

或者,如果您不需要包含 scala 库的完整 jar,而只是想打包您的代码:

$ sbt package

关于scala - 使用 SBT 或 gradle 将 scala 编译为 assembly jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33310104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com