I'm trying to add artifact to my play project, I've looked in couple of forums and looks like this is the proper way to do it:
lazy val playProject = play.Project(myProjectName, myProjectVersion, path = file("."))
.settings(addArtifact(Artifact (myProjectName, "dist", "zip"), dist).settings: _*)
but then I'm getting compilation error:
"...project/Build.scala:26: not found: value dist"
where I need to define it? what am I missing here?
additional info: my "playProject" is a module inside scala project that contain some other scala modules.
It is difficult to be sure with such a limited extract of your build definition, but my guess would be you are in a scala build file and didn't import the dist key in scope.
Try adding the following import to your build file
import com.typesafe.sbt.packager.universal.UniversalKeys.dist
addArtifact has the following signature :
def addArtifact(a : sbt.Artifact, taskDef : sbt.TaskKey[java.io.File])
UniversalKeys.dist is defined as follows:
val dist = TaskKey[File]("dist", "Creates the distribution packages.")
So the types are correct at least :)
Related
So I'm pretty new at scala. I'm trying to use this library in my other project: https://www.github.com/desmondyeung/scala-hashing
I downloaded it, and looked up a guide on how to use downloaded projects (https://www.oreilly.com/library/view/scala-cookbook/9781449340292/ch18s11.html), and it said to make a build.scala and then put some such in it. The way I've tried to do that is this:
import sbt._
object MyBuild extends Build {
lazy val root = Project("root", file(".")) dependsOn(xxHash)
lazy val xxHash = RootProject(uri("file:///Users/[other stuff]/documents/GitHub/scala-hashing-master/project"))
}
And that's all that's in that build.scala file. It's under the project folder.
I tried to run it using some simple test code:
import xxHash._
object hashtest {
def main(): Unit = {
println(XxHash.com.desmondyeung.hashing.Xxhash64.hashByteArray(Array[Byte](xs = 123), seed = 0))
}
}
But I'm getting an error, it says "not found: object xxHash". I must be missing something, because the guide doesn't tell me how to reference it I don't think? I tried just using import com.desmondyeung.hashing.XxHash64 but it didn't work either, saying object desmondyeung is not a member of package com
I googled that, and it said to try putting _root_ before .com, but that did not work.
I am working with scala and want to use SimplexSolver (https://opensource.googleblog.com/2009/06/introducing-apache-commons-math.html). I am using sbt, hence downloaded the .jar file for commons-math-2.2 and imported it in the code. Then I tried to use it, but it showed not found: type SimplexSolver. Following is the code snippet.
import org.apache.commons.math.optimization.linear
class MySimplexSolver{
val solver = new SimplexSolver()
}
I have a lib folder where all the .jar files are kept. Any help regarding this is appreciated. :)
I need to compile a scala code which calls a java code from it.
What I did:
1]I have a scala main file check.scala
package com.code
class check {
var Rectvalue = Array.ofDim[Int](5)
val str = Array.ofDim[String](1)
def nativeacces(arg: String, loop: Integer) {
val test = new testing()
test.process(arg, Rectvalue,str)
}
}
2.For creating instance val test = new testing() ,i added two .class(sample.class,testJNI.class) file from java source code inside the folder(package) com/code.
3.When I compile the scala code using
scalac check.scala
It generates the class file for the scala file.
What I have to do:
1.Instead of .class(sample.class,testJNI.class) file added inside the package ,i need to add jar file.
2.I tried, created jar file for the .class file and compile the Scala, it shows the error:
scala:6: error: not found: type testing
val test = new testing()
3.I need to link the .jar file and compile the scala main file
You can reference classes/directories/JARs via classpath option:
scalac -classpath your.jar check.scala
Related question: Adding .jar's to classpath (Scala).
If you want a proper build use SBT, put your JAR in lib directory in the root of project and it will figure out what to do for you. Here is Hello World of SBT.
I have a build setup where I have multiple groups of dependent modules. I wrote a function which produces one group of modules:
def group(id: String) = {
val module1 = project.in(s"core/$id")...
val module2 = project.in(s"impl/$id").dependsOn(module1)...
(module1, module2)
}
I would now like to declare them:
val (core2014, impl2014) = group("2014")
This does not appear to work in build.sbt:
Pattern matching in val statements is not supported
I tried moving it into project/build.scala, where it gets compiled fine, but the modules don't appear in the SBT prompt. (That is, typing core2014/compile gives not a valid key.)
Is there any way I can add modules to the build "manually", instead of relying on the autodetection of SBT?
I'm going to guess the answer is "no" for build.sbt.
But you can redefine projects in your project/Build.scala
I want to create an Action to automate GCJ compilation. Since I couldn't make it work with Ant, I decided to try SBT. The docs say how to create an Action and how to run an external process. What I don't yet see is how to reuse the directory tree traversal which exists for java and scala compiler Actions. In this case my input files would be all the .class files under a certain root folder. I would also need to specify a specific classpath for GCJ. Any pointers for this would be appreciated too.
I haven't used GCJ much at all and I'm still pretty new at SBT, but this is how I believe you could write a quick task to do exactly what you are looking for with SBT 0.7.1. You can use a PathFinder to grab all of the class files like so:
val allClasses = (outputPath ##) ** "*.class"
Using that PathFinder and the "compileClasspath" top level method, you can construct a task like this which will run gcj using the current project's classpath and compose all of the .class files into one gcjFile:
val gcj = "/usr/local/bin/gcj"
val gcjFile = "target/my_executable.o"
val allClasses = (outputPath ##) ** "*.class"
lazy val gcjCompile = execTask {
<x>{gcj} --classpath={compileClasspath.get.map(_.absolutePath).mkString(":")} -c {allClasses.get.map(_.absolutePath).mkString("-c ")} -o {gcjFile}</x>
} dependsOn(compile) describedAs("Create a GCJ executable object")